Skip to content

Commit 34b551b

Browse files
authored
Fix last and first error method with Dask processes scheduler (#460)
1 parent cbcc035 commit 34b551b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

flox/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ def reindex_(
892892
"Currently does not support reindexing with object arrays of tuples. "
893893
"These occur when grouping by multi-indexed variables in xarray."
894894
)
895-
if fill_value is xrdtypes.NA or isnull(fill_value):
895+
# Use '==' instead of 'is', as Dask serialization can break identity checks.
896+
if fill_value == xrdtypes.NA or isnull(fill_value):
896897
new_dtype, fill_value = xrdtypes.maybe_promote(array.dtype)
897898
else:
898899
new_dtype = array.dtype
@@ -1380,7 +1381,8 @@ def _finalize_results(
13801381
if fill_value is None:
13811382
raise ValueError("Filling is required but fill_value is None.")
13821383
# This allows us to match xarray's type promotion rules
1383-
if fill_value is xrdtypes.NA:
1384+
# Use '==' instead of 'is', as Dask serialization can break identity checks.
1385+
if fill_value == xrdtypes.NA:
13841386
new_dtype, fill_value = xrdtypes.maybe_promote(finalized[agg.name].dtype)
13851387
finalized[agg.name] = finalized[agg.name].astype(new_dtype)
13861388

tests/test_xarray.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,3 +798,16 @@ def test_groupby_preserve_dtype(reduction):
798798
expected = getattr(np, reduction)(ds.test.data, axis=0).dtype
799799

800800
assert actual == expected
801+
802+
803+
@requires_dask
804+
def test_resample_first_last_empty():
805+
with xr.set_options(use_flox=True), dask.config.set(scheduler="processes"):
806+
arr = xr.DataArray(
807+
np.nan,
808+
coords={
809+
"date": pd.to_datetime(["2025-03-24", "2025-06-23"]),
810+
},
811+
dims=["date"],
812+
).chunk(date=(1, 1))
813+
arr.resample(date="QE").last().compute()

0 commit comments

Comments
 (0)