Skip to content

Commit

Permalink
Fix default int on windows, numpy<2 (#395)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dcherian committed Sep 17, 2024
1 parent d65181c commit 8556811
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- os: "ubuntu-latest"
env: "minimal-requirements"
python-version: "3.10"
- os: "windows-latest"
env: "env-numpy1"
python-version: "3.10"
steps:
- uses: actions/checkout@v4
with:
Expand Down
30 changes: 30 additions & 0 deletions ci/env-numpy1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: flox-tests
channels:
- conda-forge
dependencies:
- asv
- cachey
- cftime
- codecov
- cubed>=0.14.3
- dask-core
- pandas
- numpy<2
- scipy
- lxml # for mypy coverage report
- matplotlib
- pip
- pytest
- pytest-cov
- pytest-pretty
- pytest-xdist
- syrupy
- pre-commit
- numpy_groupies>=0.9.19
- pooch
- toolz
- numba
- numbagg>=0.3
- hypothesis
- pip:
- git+https://github.com/dcherian/xarray.git@flox-preserve-dtype
8 changes: 4 additions & 4 deletions flox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ def groupby_reduce(
)

is_bool_array = np.issubdtype(array.dtype, bool)
array = array.astype(np.intp) if is_bool_array else array
array = array.astype(np.int_) if is_bool_array else array

isbins = _atleast_1d(isbin, nby)

Expand Down Expand Up @@ -2778,7 +2778,7 @@ def groupby_scan(
return array

is_bool_array = np.issubdtype(array.dtype, bool)
array = array.astype(np.intp) if is_bool_array else array
array = array.astype(np.int_) if is_bool_array else array

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

Expand Down
4 changes: 2 additions & 2 deletions flox/xrdtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def _maybe_promote_int(dtype) -> np.dtype:
if not isinstance(dtype, np.dtype):
dtype = np.dtype(dtype)
if dtype.kind == "i":
dtype = np.result_type(dtype, np.intp)
dtype = np.result_type(dtype, np.int_)
elif dtype.kind == "u":
dtype = np.result_type(dtype, np.uintp)
dtype = np.result_type(dtype, np.uint)
return dtype


Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
settings.register_profile(
"default",
max_examples=300,
deadline=500,
suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow],
verbosity=Verbosity.verbose,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,4 +2005,4 @@ def test_blockwise_avoid_rechunk():
by = np.array(["1", "1", "0", "", "0", ""], dtype="<U1")
actual, groups = groupby_reduce(array, by, func="first")
assert_equal(groups, ["", "0", "1"])
assert_equal(actual, [0, 0, 0])
assert_equal(actual, np.array([0, 0, 0], dtype=np.int64))

0 comments on commit 8556811

Please sign in to comment.