-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compat: Support dask query-planning, drop Python 3.9 #171
Open
hoxbro
wants to merge
19
commits into
main
Choose a base branch
from
dask_expr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f365d29
compat: Support dask query-planning
hoxbro 19afd85
update imports
hoxbro 43e6463
rename make_meta_dispatch.register(...) -> make_meta_dispatch(...)
hoxbro 589ded7
use make_meta_obj
hoxbro c7f4108
More registers
hoxbro fab8349
update test action
hoxbro b43b4c1
Update to use dd.partitionquantiles
hoxbro f4164b3
Update partitionquantiles to new method
hoxbro d229062
clean up
hoxbro 805dbe9
Remove int conversion for f-string
hoxbro 3ce10db
Ignore userwarning when using to_parquet
hoxbro 8e1f92d
Add np.ndarray
hoxbro cc4aed5
Update pyproject.toml
hoxbro 7c00186
Disable Python 3.10 linting rules for now
hoxbro 76ecbe9
dask-scheduler as single-threaded for examples
hoxbro 2ffea47
Bump minimum version dependencies to match dask
hoxbro 4ccf675
Remove pandas 1.2 compability
hoxbro 7385cb8
Reduce warning to only be the current case
hoxbro 6d5a3de
Move to filterwarning to pyproject.toml
hoxbro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
|
@@ -13,25 +13,22 @@ | |
from dask import delayed | ||
from dask.dataframe.core import get_parallel_type | ||
from dask.dataframe.extensions import make_array_nonempty | ||
from dask.dataframe.partitionquantiles import partition_quantiles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was removed when they dropped the legacy implementation: |
||
from dask.dataframe.utils import make_meta_obj, meta_nonempty | ||
from packaging.version import Version | ||
from retrying import retry | ||
|
||
try: | ||
from dask.dataframe.backends import meta_nonempty | ||
from dask.dataframe.dispatch import make_meta_dispatch | ||
except ImportError: | ||
from dask.dataframe.utils import make_meta as make_meta_dispatch, meta_nonempty | ||
|
||
from .geodataframe import GeoDataFrame | ||
from .geometry.base import GeometryDtype, _BaseCoordinateIndexer | ||
from .geoseries import GeoSeries | ||
from .spatialindex import HilbertRtree | ||
|
||
|
||
class DaskGeoSeries(dd.Series): | ||
def __init__(self, dsk, name, meta, divisions, *args, **kwargs): | ||
super().__init__(dsk, name, meta, divisions) | ||
|
||
_partition_type = GeoSeries | ||
|
||
def __init__(self, expr, *args, **kwargs): | ||
super().__init__(expr, *args, **kwargs) | ||
|
||
# Init backing properties | ||
self._partition_bounds = None | ||
|
@@ -105,7 +102,7 @@ def persist(self, **kwargs): | |
) | ||
|
||
|
||
@make_meta_dispatch.register(GeoSeries) | ||
@make_meta_obj.register(GeoSeries) | ||
def make_meta_series(s, index=None): | ||
result = s.head(0) | ||
if index is not None: | ||
|
@@ -119,13 +116,20 @@ def meta_nonempty_series(s, index=None): | |
|
||
|
||
@get_parallel_type.register(GeoSeries) | ||
def get_parallel_type_dataframe(df): | ||
def get_parallel_type_series(df): | ||
return DaskGeoSeries | ||
|
||
|
||
@dd.get_collection_type.register(GeoSeries) | ||
def get_collection_type_series(df): | ||
return DaskGeoSeries | ||
|
||
|
||
class DaskGeoDataFrame(dd.DataFrame): | ||
def __init__(self, dsk, name, meta, divisions): | ||
super().__init__(dsk, name, meta, divisions) | ||
_partition_type = GeoDataFrame | ||
|
||
def __init__(self, expr, *args, **kwargs): | ||
super().__init__(expr, *args, **kwargs) | ||
self._partition_sindex = {} | ||
self._partition_bounds = {} | ||
|
||
|
@@ -312,8 +316,9 @@ def move_retry(p1, p2): | |
ddf = self._with_hilbert_distance_column(p) | ||
|
||
# Compute output hilbert_distance divisions | ||
quantiles = partition_quantiles( | ||
ddf.hilbert_distance, npartitions | ||
from dask.dataframe.dask_expr import RepartitionQuantiles, new_collection | ||
quantiles = new_collection( | ||
RepartitionQuantiles(ddf.hilbert_distance, npartitions) | ||
).compute().values | ||
|
||
# Add _partition column containing output partition number of each row | ||
|
@@ -328,7 +333,7 @@ def move_retry(p1, p2): | |
for out_partition in out_partitions | ||
] | ||
part_output_paths = [ | ||
os.path.join(path, f"part.{int(out_partition)}.parquet") | ||
os.path.join(path, f"part.{out_partition}.parquet") | ||
for out_partition in out_partitions | ||
] | ||
|
||
|
@@ -338,7 +343,7 @@ def move_retry(p1, p2): | |
rm_retry(path) | ||
|
||
for out_partition in out_partitions: | ||
part_dir = os.path.join(path, f"part.{int(out_partition)}.parquet" ) | ||
part_dir = os.path.join(path, f"part.{out_partition}.parquet" ) | ||
mkdirs_retry(part_dir) | ||
tmp_part_dir = tempdir_format.format(partition=out_partition, uuid=dataset_uuid) | ||
mkdirs_retry(tmp_part_dir) | ||
|
@@ -360,7 +365,7 @@ def process_partition(df, i): | |
for out_partition, df_part in df.groupby('_partition'): | ||
part_path = os.path.join( | ||
tempdir_format.format(partition=out_partition, uuid=dataset_uuid), | ||
f'part{int(i)}.parquet', | ||
f'part{i}.parquet', | ||
) | ||
df_part = ( | ||
df_part | ||
|
@@ -584,7 +589,7 @@ def __getitem__(self, key): | |
return result | ||
|
||
|
||
@make_meta_dispatch.register(GeoDataFrame) | ||
@make_meta_obj.register(GeoDataFrame) | ||
def make_meta_dataframe(df, index=None): | ||
result = df.head(0) | ||
if index is not None: | ||
|
@@ -598,10 +603,14 @@ def meta_nonempty_dataframe(df, index=None): | |
|
||
|
||
@get_parallel_type.register(GeoDataFrame) | ||
def get_parallel_type_series(s): | ||
def get_parallel_type_dataframe(s): | ||
return DaskGeoDataFrame | ||
|
||
|
||
@dd.get_collection_type.register(GeoDataFrame) | ||
def get_collection_type_dataframe(df): | ||
return DaskGeoDataFrame | ||
|
||
class _DaskCoordinateIndexer(_BaseCoordinateIndexer): | ||
def __init__(self, obj, sindex): | ||
super().__init__(sindex) | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dask 2025.1 only supports Python 3.10.