Coverage for src/ipyvizzu/data/converters/converter.py: 100%
21 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 10:12 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 10:12 +0000
1"""
2This module provides the `ToSeriesListConverter` abstract class.
3"""
5from abc import ABC, abstractmethod
6from typing import Any, List, Optional, Tuple, Union
8from ipyvizzu.data.infer_type import InferType
9from ipyvizzu.data.type_alias import (
10 DimensionValue,
11 MeasureValue,
12 Series,
13 SeriesValues,
14)
17class ToSeriesListConverter(ABC):
18 """
19 Converts data into a list of dictionaries representing series.
20 Each dictionary contains information about the series `name`, `values` and `type`.
21 """
23 # pylint: disable=too-few-public-methods
25 def __init__(
26 self,
27 default_measure_value: MeasureValue,
28 default_dimension_value: DimensionValue,
29 ) -> None:
30 self._default_measure_value = default_measure_value
31 self._default_dimension_value = default_dimension_value
33 @abstractmethod
34 def get_series_list(self) -> List[Series]:
35 """
36 Convert data to a list of dictionaries representing series.
38 Returns:
39 A list of dictionaries representing series,
40 where each dictionary has `name`, `values` and `type` keys.
41 """
43 @abstractmethod
44 def _convert_to_series_values_and_type(
45 self, obj: Any
46 ) -> Tuple[SeriesValues, InferType]:
47 """
48 Convert object to SeriesValues and InferType.
49 """
51 @abstractmethod
52 def _convert_to_measure_values(self, obj: Any) -> List[MeasureValue]:
53 """
54 Convert object to a list of MeasureValue.
55 """
57 @abstractmethod
58 def _convert_to_dimension_values(self, obj: Any) -> List[DimensionValue]:
59 """
60 Convert object to a list of DimensionValue.
61 """
63 def _convert_to_series(
64 self,
65 name: Union[str, int],
66 values: SeriesValues,
67 infer_type: InferType,
68 unit: Optional[str] = None,
69 ) -> Series:
70 series = {
71 "name": str(name),
72 "values": values,
73 "type": infer_type.value,
74 }
75 if unit is not None:
76 series["unit"] = unit
77 return series