hopeit.dataframes 0.25.0b6__tar.gz → 0.25.0b9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/PKG-INFO +3 -4
  2. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/setup.py +1 -2
  3. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/dataframe.py +27 -14
  4. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/serialization/dataset.py +2 -2
  5. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/serialization/files.py +2 -5
  6. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/serialization/settings.py +1 -2
  7. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit.dataframes.egg-info/PKG-INFO +3 -4
  8. hopeit_dataframes-0.25.0b9/src/hopeit.dataframes.egg-info/requires.txt +6 -0
  9. hopeit_dataframes-0.25.0b6/src/hopeit.dataframes.egg-info/requires.txt +0 -6
  10. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/README.md +0 -0
  11. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/setup.cfg +0 -0
  12. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/__init__.py +0 -0
  13. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/py.typed +0 -0
  14. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/serialization/__init__.py +0 -0
  15. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/setup/__init__.py +0 -0
  16. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit/dataframes/setup/dataframes.py +0 -0
  17. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit.dataframes.egg-info/SOURCES.txt +0 -0
  18. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit.dataframes.egg-info/dependency_links.txt +0 -0
  19. {hopeit_dataframes-0.25.0b6 → hopeit_dataframes-0.25.0b9}/src/hopeit.dataframes.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hopeit.dataframes
3
- Version: 0.25.0b6
3
+ Version: 0.25.0b9
4
4
  Summary: Hopeit Engine Dataframes Toolkit
5
5
  Home-page: https://github.com/hopeit-git/hopeit.engine
6
6
  Author: Leo Smerling and Pablo Canto
@@ -13,7 +13,6 @@ Project-URL: GitHub: repo, https://github.com/hopeit-git/hopeit.engine
13
13
  Classifier: License :: OSI Approved :: Apache Software License
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Programming Language :: Python
16
- Classifier: Programming Language :: Python :: 3.8
17
16
  Classifier: Programming Language :: Python :: 3.9
18
17
  Classifier: Programming Language :: Python :: 3.10
19
18
  Classifier: Programming Language :: Python :: 3.11
@@ -24,9 +23,9 @@ Classifier: Operating System :: Microsoft :: Windows
24
23
  Classifier: Topic :: Internet :: WWW/HTTP
25
24
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
25
  Classifier: Framework :: AsyncIO
27
- Requires-Python: >=3.8
26
+ Requires-Python: >=3.9
28
27
  Description-Content-Type: text/markdown
29
- Requires-Dist: hopeit.engine[fs-storage]==0.25.0b6
28
+ Requires-Dist: hopeit.engine[fs-storage]==0.25.0b9
30
29
  Requires-Dist: pandas
31
30
  Requires-Dist: numpy
32
31
  Provides-Extra: pyarrow
@@ -18,7 +18,6 @@ setuptools.setup(
18
18
  "License :: OSI Approved :: Apache Software License",
19
19
  "Intended Audience :: Developers",
20
20
  "Programming Language :: Python",
21
- "Programming Language :: Python :: 3.8",
22
21
  "Programming Language :: Python :: 3.9",
23
22
  "Programming Language :: Python :: 3.10",
24
23
  "Programming Language :: Python :: 3.11",
@@ -46,7 +45,7 @@ setuptools.setup(
46
45
  package_data={
47
46
  "hopeit.dataframes": ["py.typed"],
48
47
  },
49
- python_requires=">=3.8",
48
+ python_requires=">=3.9",
50
49
  install_requires=[
51
50
  f"hopeit.engine[fs-storage]=={version['ENGINE_VERSION']}",
52
51
  "pandas",
@@ -1,8 +1,10 @@
1
1
  """
2
2
  DataFrames type abstractions.
3
3
  """
4
+
4
5
  import dataclasses
5
6
  from datetime import date, datetime, timezone
7
+ from functools import partial
6
8
  from typing import Any, Callable, Dict, Generic, Iterator, List, Type, TypeVar
7
9
 
8
10
  import numpy as np
@@ -23,11 +25,27 @@ DataFrameT = TypeVar("DataFrameT")
23
25
 
24
26
 
25
27
  @dataclasses.dataclass
26
- class DataFrameMetadata():
28
+ class DataFrameMetadata:
27
29
  columns: List[str]
28
30
  fields: Dict[str, FieldInfo]
29
31
 
30
32
 
33
+ # Functions to do type coercion
34
+ def _series_to_int(x: pd.Series) -> pd.Series:
35
+ return x.astype(np.int64)
36
+
37
+
38
+ def _series_to_float(x: pd.Series) -> pd.Series:
39
+ return x.astype(np.float64)
40
+
41
+
42
+ def _series_to_str(x: pd.Series) -> pd.Series:
43
+ return x.astype(str)
44
+
45
+
46
+ _series_to_utc_datetime = partial(pd.to_datetime, utc=True)
47
+
48
+
31
49
  class DataFrameMixin(Generic[DataFrameT, DataObject]):
32
50
  """
33
51
  MixIn class to add functionality for DataFrames dataobjects
@@ -36,11 +54,11 @@ class DataFrameMixin(Generic[DataFrameT, DataObject]):
36
54
  """
37
55
 
38
56
  DATATYPE_MAPPING = {
39
- int: lambda x: x.astype(np.int64),
40
- float: lambda x: x.astype(np.float64),
41
- str: lambda x: x.astype(str),
57
+ int: _series_to_int,
58
+ float: _series_to_float,
59
+ str: _series_to_str,
42
60
  date: pd.to_datetime,
43
- datetime: pd.to_datetime,
61
+ datetime: _series_to_utc_datetime,
44
62
  }
45
63
 
46
64
  def __init__(self) -> None:
@@ -51,9 +69,7 @@ class DataFrameMixin(Generic[DataFrameT, DataObject]):
51
69
  raise NotImplementedError # must use @dataframe decorator # pragma: no cover
52
70
 
53
71
  @staticmethod
54
- def __init_from_series__(
55
- self, **series: pd.Series
56
- ): # pylint: disable=bad-staticmethod-argument
72
+ def __init_from_series__(self, **series: pd.Series): # pylint: disable=bad-staticmethod-argument
57
73
  df = pd.DataFrame(series)
58
74
  df.index.name = None # Removes index name to avoid colisions with series name
59
75
  if self.__data_object__["validate"]:
@@ -89,10 +105,7 @@ class DataFrameMixin(Generic[DataFrameT, DataObject]):
89
105
  return self._from_df(self.__df[key])
90
106
 
91
107
  def _to_dataobjects(self) -> List[DataObject]:
92
- return [
93
- self.DataObject(**fields)
94
- for fields in self.__df.to_dict(orient="records")
95
- ]
108
+ return [self.DataObject(**fields) for fields in self.__df.to_dict(orient="records")]
96
109
 
97
110
  def event_id(self, *args, **kwargs) -> str:
98
111
  return ""
@@ -136,7 +149,7 @@ def dataframe(
136
149
  if hasattr(cls, "__annotations__") and hasattr(cls, "__dataclass_fields__"):
137
150
  amended_class = type(
138
151
  cls.__name__,
139
- (DataFrameMixin, ) + cls.__mro__,
152
+ (DataFrameMixin,) + cls.__mro__,
140
153
  dict(cls.__dict__),
141
154
  )
142
155
  setattr(amended_class, "__init__", DataFrameMixin.__init_from_series__)
@@ -145,7 +158,7 @@ def dataframe(
145
158
 
146
159
  def add_dataframe_metadata(cls):
147
160
  serialized_fields = {k: (v.annotation, v) for k, v in fields(cls).items()}
148
- dataobject_type = create_model(cls.__name__+"DataObject", **serialized_fields)
161
+ dataobject_type = create_model(cls.__name__ + "DataObject", **serialized_fields)
149
162
  dataobject_type = dataobject(dataobject_type, unsafe=True)
150
163
 
151
164
  setattr(cls, "DataObject", dataobject_type)
@@ -1,5 +1,4 @@
1
- """Dataset objects definition, used as a result of serialized dataframes
2
- """
1
+ """Dataset objects definition, used as a result of serialized dataframes"""
3
2
 
4
3
  from importlib import import_module
5
4
  from typing import Generic, Type, TypeVar
@@ -13,6 +12,7 @@ DataFrameT = TypeVar("DataFrameT")
13
12
  @dataclass
14
13
  class Dataset(Generic[DataFrameT]):
15
14
  """Persisted representation of a @dataframe object"""
15
+
16
16
  protocol: str
17
17
  partition_key: str
18
18
  key: str
@@ -1,5 +1,4 @@
1
- """Support for `@dataframes` serialization to files
2
- """
1
+ """Support for `@dataframes` serialization to files"""
3
2
 
4
3
  import io
5
4
  from importlib import import_module
@@ -59,9 +58,7 @@ class DatasetFileStorage(Generic[DataFrameT]):
59
58
  async def load(self, dataset: Dataset) -> EventPayloadType:
60
59
  """Loads @dataframe annotated object using Dataset metadata"""
61
60
  datatype: Type[DataFrameT] = find_dataframe_type(dataset.datatype)
62
- data = await self.storage.get_file(
63
- dataset.key, partition_key=dataset.partition_key
64
- )
61
+ data = await self.storage.get_file(dataset.key, partition_key=dataset.partition_key)
65
62
  if data is None:
66
63
  raise FileNotFoundError(dataset.key)
67
64
  df = pd.read_parquet(io.BytesIO(data), engine="pyarrow")
@@ -1,5 +1,4 @@
1
- """Support for plugin configuration
2
- """
1
+ """Support for plugin configuration"""
3
2
 
4
3
  from typing import Optional
5
4
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hopeit.dataframes
3
- Version: 0.25.0b6
3
+ Version: 0.25.0b9
4
4
  Summary: Hopeit Engine Dataframes Toolkit
5
5
  Home-page: https://github.com/hopeit-git/hopeit.engine
6
6
  Author: Leo Smerling and Pablo Canto
@@ -13,7 +13,6 @@ Project-URL: GitHub: repo, https://github.com/hopeit-git/hopeit.engine
13
13
  Classifier: License :: OSI Approved :: Apache Software License
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Programming Language :: Python
16
- Classifier: Programming Language :: Python :: 3.8
17
16
  Classifier: Programming Language :: Python :: 3.9
18
17
  Classifier: Programming Language :: Python :: 3.10
19
18
  Classifier: Programming Language :: Python :: 3.11
@@ -24,9 +23,9 @@ Classifier: Operating System :: Microsoft :: Windows
24
23
  Classifier: Topic :: Internet :: WWW/HTTP
25
24
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
25
  Classifier: Framework :: AsyncIO
27
- Requires-Python: >=3.8
26
+ Requires-Python: >=3.9
28
27
  Description-Content-Type: text/markdown
29
- Requires-Dist: hopeit.engine[fs-storage]==0.25.0b6
28
+ Requires-Dist: hopeit.engine[fs-storage]==0.25.0b9
30
29
  Requires-Dist: pandas
31
30
  Requires-Dist: numpy
32
31
  Provides-Extra: pyarrow
@@ -0,0 +1,6 @@
1
+ hopeit.engine[fs-storage]==0.25.0b9
2
+ pandas
3
+ numpy
4
+
5
+ [pyarrow]
6
+ pyarrow
@@ -1,6 +0,0 @@
1
- hopeit.engine[fs-storage]==0.25.0b6
2
- pandas
3
- numpy
4
-
5
- [pyarrow]
6
- pyarrow