Skip to content

Commit 8556811

Browse files
authored
Fix default int on windows, numpy<2 (#395)
* Avoid rechunking when preferred_method="blockwise" * Add new numpy1 environment * try int_ instead of intp * Use uintp instead * Use np.uint instead * more fixes * Add test * fix * fix again
1 parent d65181c commit 8556811

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

.github/workflows/ci.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- os: "ubuntu-latest"
3838
env: "minimal-requirements"
3939
python-version: "3.10"
40+
- os: "windows-latest"
41+
env: "env-numpy1"
42+
python-version: "3.10"
4043
steps:
4144
- uses: actions/checkout@v4
4245
with:

ci/env-numpy1.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: flox-tests
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- asv
6+
- cachey
7+
- cftime
8+
- codecov
9+
- cubed>=0.14.3
10+
- dask-core
11+
- pandas
12+
- numpy<2
13+
- scipy
14+
- lxml # for mypy coverage report
15+
- matplotlib
16+
- pip
17+
- pytest
18+
- pytest-cov
19+
- pytest-pretty
20+
- pytest-xdist
21+
- syrupy
22+
- pre-commit
23+
- numpy_groupies>=0.9.19
24+
- pooch
25+
- toolz
26+
- numba
27+
- numbagg>=0.3
28+
- hypothesis
29+
- pip:
30+
- git+https://github.com/dcherian/xarray.git@flox-preserve-dtype

flox/core.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ def groupby_reduce(
24192419
)
24202420

24212421
is_bool_array = np.issubdtype(array.dtype, bool)
2422-
array = array.astype(np.intp) if is_bool_array else array
2422+
array = array.astype(np.int_) if is_bool_array else array
24232423

24242424
isbins = _atleast_1d(isbin, nby)
24252425

@@ -2778,7 +2778,7 @@ def groupby_scan(
27782778
return array
27792779

27802780
is_bool_array = np.issubdtype(array.dtype, bool)
2781-
array = array.astype(np.intp) if is_bool_array else array
2781+
array = array.astype(np.int_) if is_bool_array else array
27822782

27832783
if expected_groups is not None:
27842784
raise NotImplementedError("Setting `expected_groups` and binning is not supported yet.")
@@ -2812,9 +2812,9 @@ def groupby_scan(
28122812
# it defaults to the dtype of a, unless a
28132813
# has an integer dtype with a precision less than that of the default platform integer.
28142814
if array.dtype.kind == "i":
2815-
agg.dtype = np.result_type(array.dtype, np.intp)
2815+
agg.dtype = np.result_type(array.dtype, np.int_)
28162816
elif array.dtype.kind == "u":
2817-
agg.dtype = np.result_type(array.dtype, np.uintp)
2817+
agg.dtype = np.result_type(array.dtype, np.uint)
28182818
else:
28192819
agg.dtype = array.dtype if dtype is None else dtype
28202820

flox/xrdtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ def _maybe_promote_int(dtype) -> np.dtype:
179179
if not isinstance(dtype, np.dtype):
180180
dtype = np.dtype(dtype)
181181
if dtype.kind == "i":
182-
dtype = np.result_type(dtype, np.intp)
182+
dtype = np.result_type(dtype, np.int_)
183183
elif dtype.kind == "u":
184-
dtype = np.result_type(dtype, np.uintp)
184+
dtype = np.result_type(dtype, np.uint)
185185
return dtype
186186

187187

tests/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
settings.register_profile(
1313
"default",
1414
max_examples=300,
15+
deadline=500,
1516
suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow],
1617
verbosity=Verbosity.verbose,
1718
)

tests/test_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2005,4 +2005,4 @@ def test_blockwise_avoid_rechunk():
20052005
by = np.array(["1", "1", "0", "", "0", ""], dtype="<U1")
20062006
actual, groups = groupby_reduce(array, by, func="first")
20072007
assert_equal(groups, ["", "0", "1"])
2008-
assert_equal(actual, [0, 0, 0])
2008+
assert_equal(actual, np.array([0, 0, 0], dtype=np.int64))

0 commit comments

Comments
 (0)