-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
from dask.dataframe.extensions import make_array_nonempty, make_scalar, register_series_accessor | ||
import nested_pandas as npd | ||
from nested_pandas import NestedDtype, NestSeriesAccessor | ||
import dask | ||
from dask.dataframe.extensions import register_series_accessor | ||
from nested_pandas import NestedDtype | ||
|
||
|
||
@register_series_accessor("nest") | ||
class DaskNestSeriesAccessor(npd.NestSeriesAccessor): | ||
|
||
"""The nested-dask version of the nested-pandas NestSeriesAccessor. | ||
Note that this has a very limited implementation relative to nested-pandas. | ||
Parameters | ||
---------- | ||
series: dd.series | ||
A series to tie to the accessor | ||
""" | ||
|
||
def __init__(self, series): | ||
self._check_series(series) | ||
|
||
self._series = series | ||
|
||
@staticmethod | ||
def _check_series(series): | ||
"""chcek the validity of the tied series dtype""" | ||
dtype = series.dtype | ||
if not isinstance(dtype, NestedDtype): | ||
raise AttributeError(f"Can only use .nest accessor with a Series of NestedDtype, got {dtype}") | ||
|
||
@property | ||
def fields(self) -> list[str]: | ||
"""Names of the nested columns""" | ||
return self._series.head(0).nest.fields | ||
#hacky | ||
#return self._series.partitions[0:1].map_partitions(lambda x: x.nest.fields) | ||
#return self._series.array.field_names | ||
|
||
@dask.delayed | ||
def test_fields(self): | ||
return self._series.head(0).nest.fields | ||
|
||
return self._series.head(0).nest.fields # hacky |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters