Skip to content

Commit 9c72866

Browse files
authored
bump min deps for 0.15 (#3713)
* Bump numpy to 1.15, pandas to 0.25, scipy to 1.2 * Remove some backcompat code * bump pandas in doc.yml * Fix repr test * review cleanups. * scipy to 1.3 * Revert "bump pandas in doc.yml" This reverts commit d078cf1. * bugfix. * fix tests. * update setup.cfg * Update whats-new
1 parent ecd67f4 commit 9c72866

14 files changed

+51
-54
lines changed

ci/requirements/py36-bare-minimum.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ dependencies:
77
- pytest
88
- pytest-cov
99
- pytest-env
10-
- numpy=1.14
11-
- pandas=0.24
10+
- numpy=1.15
11+
- pandas=0.25

ci/requirements/py36-min-all-deps.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ dependencies:
2929
- nc-time-axis=1.2
3030
- netcdf4=1.4
3131
- numba=0.44
32-
- numpy=1.14
33-
- pandas=0.24
32+
- numpy=1.15
33+
- pandas=0.25
3434
# - pint # See py36-min-nep18.yml
3535
- pip
3636
- pseudonetcdf=3.0
@@ -40,7 +40,7 @@ dependencies:
4040
- pytest-cov
4141
- pytest-env
4242
- rasterio=1.0
43-
- scipy=1.0 # Policy allows for 1.2, but scipy>=1.1 breaks numpy=1.14
43+
- scipy=1.3
4444
- seaborn=0.9
4545
# - sparse # See py36-min-nep18.yml
4646
- toolz=0.10

ci/requirements/py36-min-nep18.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- dask=2.4
1010
- distributed=2.4
1111
- numpy=1.17
12-
- pandas=0.24
12+
- pandas=0.25
1313
- pint=0.9 # Actually not enough as it doesn't implement __array_function__yet!
1414
- pytest
1515
- pytest-cov

doc/installing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Required dependencies
77
---------------------
88

99
- Python (3.6 or later)
10-
- `numpy <http://www.numpy.org/>`__ (1.14 or later)
11-
- `pandas <http://pandas.pydata.org/>`__ (0.24 or later)
10+
- `numpy <http://www.numpy.org/>`__ (1.15 or later)
11+
- `pandas <http://pandas.pydata.org/>`__ (0.25 or later)
1212

1313
Optional dependencies
1414
---------------------

doc/whats-new.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ v0.15.0 (unreleased)
2121

2222
Breaking changes
2323
~~~~~~~~~~~~~~~~
24-
- Bumped minimum ``dask`` version to 2.2.
24+
- Bumped minimum tested versions for dependencies:
25+
- numpy 1.15
26+
- pandas 0.25
27+
- dask 2.2
28+
- distributed 2.2
29+
- scipy 1.3
30+
2531
- Remove ``compat`` and ``encoding`` kwargs from ``DataArray``, which
2632
have been deprecated since 0.12. (:pull:`3650`).
2733
Instead, specify the encoding when writing to disk or set

setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ zip_safe = False # https://mypy.readthedocs.io/en/latest/installed_packages.htm
7979
include_package_data = True
8080
python_requires = >=3.6
8181
install_requires =
82-
numpy >= 1.14
83-
pandas >= 0.24
82+
numpy >= 1.15
83+
pandas >= 0.25
8484
setup_requires = setuptools_scm
8585

8686
[options.package_data]

xarray/core/dataarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,7 @@ def quantile(
29692969
29702970
See Also
29712971
--------
2972-
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile
2972+
numpy.nanquantile, pandas.Series.quantile, Dataset.quantile
29732973
29742974
Examples
29752975
--------

xarray/core/dataset.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -4466,12 +4466,7 @@ def _set_sparse_data_from_dataframe(
44664466

44674467
idx = dataframe.index
44684468
if isinstance(idx, pd.MultiIndex):
4469-
try:
4470-
codes = idx.codes
4471-
except AttributeError:
4472-
# deprecated since pandas 0.24
4473-
codes = idx.labels
4474-
coords = np.stack([np.asarray(code) for code in codes], axis=0)
4469+
coords = np.stack([np.asarray(code) for code in idx.codes], axis=0)
44754470
is_sorted = idx.is_lexsorted
44764471
else:
44774472
coords = np.arange(idx.size).reshape(1, -1)
@@ -5171,7 +5166,7 @@ def quantile(
51715166
51725167
See Also
51735168
--------
5174-
numpy.nanpercentile, pandas.Series.quantile, DataArray.quantile
5169+
numpy.nanquantile, pandas.Series.quantile, DataArray.quantile
51755170
51765171
Examples
51775172
--------

xarray/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
595595
596596
See Also
597597
--------
598-
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile,
598+
numpy.nanquantile, pandas.Series.quantile, Dataset.quantile,
599599
DataArray.quantile
600600
601601
Examples

xarray/core/nputils.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pandas as pd
55

6+
from numpy.core.multiarray import normalize_axis_index
7+
68
try:
79
import bottleneck as bn
810

@@ -13,29 +15,20 @@
1315
_USE_BOTTLENECK = False
1416

1517

16-
def _validate_axis(data, axis):
17-
ndim = data.ndim
18-
if not -ndim <= axis < ndim:
19-
raise IndexError(f"axis {axis!r} out of bounds [-{ndim}, {ndim})")
20-
if axis < 0:
21-
axis += ndim
22-
return axis
23-
24-
2518
def _select_along_axis(values, idx, axis):
2619
other_ind = np.ix_(*[np.arange(s) for s in idx.shape])
2720
sl = other_ind[:axis] + (idx,) + other_ind[axis:]
2821
return values[sl]
2922

3023

3124
def nanfirst(values, axis):
32-
axis = _validate_axis(values, axis)
25+
axis = normalize_axis_index(axis, values.ndim)
3326
idx_first = np.argmax(~pd.isnull(values), axis=axis)
3427
return _select_along_axis(values, idx_first, axis)
3528

3629

3730
def nanlast(values, axis):
38-
axis = _validate_axis(values, axis)
31+
axis = normalize_axis_index(axis, values.ndim)
3932
rev = (slice(None),) * axis + (slice(None, None, -1),)
4033
idx_last = -1 - np.argmax(~pd.isnull(values)[rev], axis=axis)
4134
return _select_along_axis(values, idx_last, axis)
@@ -186,7 +179,7 @@ def _rolling_window(a, window, axis=-1):
186179
This function is taken from https://github.com/numpy/numpy/pull/31
187180
but slightly modified to accept axis option.
188181
"""
189-
axis = _validate_axis(a, axis)
182+
axis = normalize_axis_index(axis, a.ndim)
190183
a = np.swapaxes(a, axis, -1)
191184

192185
if window < 1:

xarray/core/variable.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
17221722
17231723
See Also
17241724
--------
1725-
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile,
1725+
numpy.nanquantile, pandas.Series.quantile, Dataset.quantile,
17261726
DataArray.quantile
17271727
"""
17281728

@@ -1734,10 +1734,6 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
17341734
scalar = utils.is_scalar(q)
17351735
q = np.atleast_1d(np.asarray(q, dtype=np.float64))
17361736

1737-
# TODO: remove once numpy >= 1.15.0 is the minimum requirement
1738-
if np.count_nonzero(q < 0.0) or np.count_nonzero(q > 1.0):
1739-
raise ValueError("Quantiles must be in the range [0, 1]")
1740-
17411737
if dim is None:
17421738
dim = self.dims
17431739

@@ -1746,9 +1742,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
17461742

17471743
def _wrapper(npa, **kwargs):
17481744
# move quantile axis to end. required for apply_ufunc
1749-
1750-
# TODO: use np.nanquantile once numpy >= 1.15.0 is the minimum requirement
1751-
return np.moveaxis(np.nanpercentile(npa, **kwargs), 0, -1)
1745+
return np.moveaxis(np.nanquantile(npa, **kwargs), 0, -1)
17521746

17531747
axis = np.arange(-1, -1 * len(dim) - 1, -1)
17541748
result = apply_ufunc(
@@ -1760,7 +1754,7 @@ def _wrapper(npa, **kwargs):
17601754
output_dtypes=[np.float64],
17611755
output_sizes={"quantile": len(q)},
17621756
dask="parallelized",
1763-
kwargs={"q": q * 100, "axis": axis, "interpolation": interpolation},
1757+
kwargs={"q": q, "axis": axis, "interpolation": interpolation},
17641758
)
17651759

17661760
# for backward compatibility

xarray/plot/utils.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,6 @@ def _add_colorbar(primitive, ax, cbar_ax, cbar_kwargs, cmap_params):
583583

584584
def _rescale_imshow_rgb(darray, vmin, vmax, robust):
585585
assert robust or vmin is not None or vmax is not None
586-
# TODO: remove when min numpy version is bumped to 1.13
587-
# There's a cyclic dependency via DataArray, so we can't import from
588-
# xarray.ufuncs in global scope.
589-
from xarray.ufuncs import maximum, minimum
590586

591587
# Calculate vmin and vmax automatically for `robust=True`
592588
if robust:
@@ -615,9 +611,7 @@ def _rescale_imshow_rgb(darray, vmin, vmax, robust):
615611
# After scaling, downcast to 32-bit float. This substantially reduces
616612
# memory usage after we hand `darray` off to matplotlib.
617613
darray = ((darray.astype("f8") - vmin) / (vmax - vmin)).astype("f4")
618-
with warnings.catch_warnings():
619-
warnings.filterwarnings("ignore", "xarray.ufuncs", PendingDeprecationWarning)
620-
return minimum(maximum(darray, 0), 1)
614+
return np.minimum(np.maximum(darray, 0), 1)
621615

622616

623617
def _update_axes(

xarray/tests/test_dataarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_repr_multiindex(self):
8080
assert expected == repr(self.mda)
8181

8282
@pytest.mark.skipif(
83-
LooseVersion(np.__version__) < "1.15",
83+
LooseVersion(np.__version__) < "1.16",
8484
reason="old versions of numpy have different printing behavior",
8585
)
8686
def test_repr_multiindex_long(self):

xarray/tests/test_units.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,10 @@ def test_squeeze(self, dtype):
18381838
"func",
18391839
(
18401840
method("coarsen", windows={"y": 2}, func=np.mean),
1841-
method("quantile", q=[0.25, 0.75]),
1841+
pytest.param(
1842+
method("quantile", q=[0.25, 0.75]),
1843+
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
1844+
),
18421845
pytest.param(
18431846
method("rank", dim="x"),
18441847
marks=pytest.mark.xfail(reason="rank not implemented for non-ndarray"),
@@ -3401,7 +3404,10 @@ def test_stacking_reordering(self, func, dtype):
34013404
method("diff", dim="x"),
34023405
method("differentiate", coord="x"),
34033406
method("integrate", dim="x"),
3404-
method("quantile", q=[0.25, 0.75]),
3407+
pytest.param(
3408+
method("quantile", q=[0.25, 0.75]),
3409+
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
3410+
),
34053411
method("reduce", func=np.sum, dim="x"),
34063412
pytest.param(
34073413
lambda x: x.dot(x),
@@ -3491,7 +3497,10 @@ def test_resample(self, dtype):
34913497
method("assign_coords", z=(["x"], np.arange(5) * unit_registry.s)),
34923498
method("first"),
34933499
method("last"),
3494-
method("quantile", q=np.array([0.25, 0.5, 0.75]), dim="x"),
3500+
pytest.param(
3501+
method("quantile", q=[0.25, 0.5, 0.75], dim="x"),
3502+
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
3503+
),
34953504
),
34963505
ids=repr,
34973506
)
@@ -4929,7 +4938,10 @@ def test_reindex_like(self, unit, error, dtype):
49294938
method("diff", dim="x"),
49304939
method("differentiate", coord="x"),
49314940
method("integrate", coord="x"),
4932-
method("quantile", q=[0.25, 0.75]),
4941+
pytest.param(
4942+
method("quantile", q=[0.25, 0.75]),
4943+
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
4944+
),
49334945
method("reduce", func=np.sum, dim="x"),
49344946
method("map", np.fabs),
49354947
),
@@ -5039,7 +5051,10 @@ def test_resample(self, dtype):
50395051
method("assign_coords", v=("x", np.arange(10) * unit_registry.s)),
50405052
method("first"),
50415053
method("last"),
5042-
method("quantile", q=[0.25, 0.5, 0.75], dim="x"),
5054+
pytest.param(
5055+
method("quantile", q=[0.25, 0.5, 0.75], dim="x"),
5056+
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
5057+
),
50435058
),
50445059
ids=repr,
50455060
)

0 commit comments

Comments
 (0)