Skip to content
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

bump min deps for 0.15 #3713

Merged
merged 13 commits into from
Jan 24, 2020
4 changes: 2 additions & 2 deletions ci/requirements/py36-bare-minimum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ dependencies:
- pytest
- pytest-cov
- pytest-env
- numpy=1.14
- pandas=0.24
- numpy=1.15
- pandas=0.25
6 changes: 3 additions & 3 deletions ci/requirements/py36-min-all-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ dependencies:
- nc-time-axis=1.2
- netcdf4=1.4
- numba=0.44
- numpy=1.14
- pandas=0.24
- numpy=1.15
- pandas=0.25
# - pint # See py36-min-nep18.yml
- pip
- pseudonetcdf=3.0
Expand All @@ -40,7 +40,7 @@ dependencies:
- pytest-cov
- pytest-env
- rasterio=1.0
- scipy=1.0 # Policy allows for 1.2, but scipy>=1.1 breaks numpy=1.14
- scipy=1.3
- seaborn=0.9
# - sparse # See py36-min-nep18.yml
- toolz=0.10
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/py36-min-nep18.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- dask=2.4
- distributed=2.4
- numpy=1.17
- pandas=0.24
- pandas=0.25
- pint=0.9 # Actually not enough as it doesn't implement __array_function__yet!
- pytest
- pytest-cov
Expand Down
4 changes: 2 additions & 2 deletions doc/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Required dependencies
---------------------

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

Optional dependencies
---------------------
Expand Down
8 changes: 7 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ v0.15.0 (unreleased)

Breaking changes
~~~~~~~~~~~~~~~~
- Bumped minimum ``dask`` version to 2.2.
- Bumped minimum tested versions for dependencies:
- numpy 1.15
- pandas 0.25
- dask 2.2
- distributed 2.2
- scipy 1.3

- Remove ``compat`` and ``encoding`` kwargs from ``DataArray``, which
have been deprecated since 0.12. (:pull:`3650`).
Instead, specify the encoding when writing to disk or set
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ zip_safe = True
include_package_data = True
python_requires = >=3.6
install_requires =
numpy >= 1.14
pandas >= 0.24
numpy >= 1.15
pandas >= 0.25
setup_requires = setuptools_scm

[options.package_data]
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2969,7 +2969,7 @@ def quantile(

See Also
--------
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile
numpy.nanquantile, pandas.Series.quantile, Dataset.quantile

Examples
--------
Expand Down
9 changes: 2 additions & 7 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4466,12 +4466,7 @@ def _set_sparse_data_from_dataframe(

idx = dataframe.index
if isinstance(idx, pd.MultiIndex):
try:
codes = idx.codes
except AttributeError:
# deprecated since pandas 0.24
codes = idx.labels
coords = np.stack([np.asarray(code) for code in codes], axis=0)
coords = np.stack([np.asarray(code) for code in idx.codes], axis=0)
is_sorted = idx.is_lexsorted
else:
coords = np.arange(idx.size).reshape(1, -1)
Expand Down Expand Up @@ -5171,7 +5166,7 @@ def quantile(

See Also
--------
numpy.nanpercentile, pandas.Series.quantile, DataArray.quantile
numpy.nanquantile, pandas.Series.quantile, DataArray.quantile

Examples
--------
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):

See Also
--------
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile,
numpy.nanquantile, pandas.Series.quantile, Dataset.quantile,
DataArray.quantile

Examples
Expand Down
17 changes: 5 additions & 12 deletions xarray/core/nputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pandas as pd

from numpy.core.multiarray import normalize_axis_index

try:
import bottleneck as bn

Expand All @@ -13,29 +15,20 @@
_USE_BOTTLENECK = False


def _validate_axis(data, axis):
ndim = data.ndim
if not -ndim <= axis < ndim:
raise IndexError(f"axis {axis!r} out of bounds [-{ndim}, {ndim})")
if axis < 0:
axis += ndim
return axis


def _select_along_axis(values, idx, axis):
other_ind = np.ix_(*[np.arange(s) for s in idx.shape])
sl = other_ind[:axis] + (idx,) + other_ind[axis:]
return values[sl]


def nanfirst(values, axis):
axis = _validate_axis(values, axis)
axis = normalize_axis_index(axis, values.ndim)
idx_first = np.argmax(~pd.isnull(values), axis=axis)
return _select_along_axis(values, idx_first, axis)


def nanlast(values, axis):
axis = _validate_axis(values, axis)
axis = normalize_axis_index(axis, values.ndim)
rev = (slice(None),) * axis + (slice(None, None, -1),)
idx_last = -1 - np.argmax(~pd.isnull(values)[rev], axis=axis)
return _select_along_axis(values, idx_last, axis)
Expand Down Expand Up @@ -186,7 +179,7 @@ def _rolling_window(a, window, axis=-1):
This function is taken from https://github.com/numpy/numpy/pull/31
but slightly modified to accept axis option.
"""
axis = _validate_axis(a, axis)
axis = normalize_axis_index(axis, a.ndim)
a = np.swapaxes(a, axis, -1)

if window < 1:
Expand Down
12 changes: 3 additions & 9 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):

See Also
--------
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile,
numpy.nanquantile, pandas.Series.quantile, Dataset.quantile,
DataArray.quantile
"""

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

# TODO: remove once numpy >= 1.15.0 is the minimum requirement
if np.count_nonzero(q < 0.0) or np.count_nonzero(q > 1.0):
raise ValueError("Quantiles must be in the range [0, 1]")

if dim is None:
dim = self.dims

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

def _wrapper(npa, **kwargs):
# move quantile axis to end. required for apply_ufunc

# TODO: use np.nanquantile once numpy >= 1.15.0 is the minimum requirement
return np.moveaxis(np.nanpercentile(npa, **kwargs), 0, -1)
return np.moveaxis(np.nanquantile(npa, **kwargs), 0, -1)

axis = np.arange(-1, -1 * len(dim) - 1, -1)
result = apply_ufunc(
Expand All @@ -1760,7 +1754,7 @@ def _wrapper(npa, **kwargs):
output_dtypes=[np.float64],
output_sizes={"quantile": len(q)},
dask="parallelized",
kwargs={"q": q * 100, "axis": axis, "interpolation": interpolation},
kwargs={"q": q, "axis": axis, "interpolation": interpolation},
)

# for backward compatibility
Expand Down
8 changes: 1 addition & 7 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,6 @@ def _add_colorbar(primitive, ax, cbar_ax, cbar_kwargs, cmap_params):

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

# Calculate vmin and vmax automatically for `robust=True`
if robust:
Expand Down Expand Up @@ -579,9 +575,7 @@ def _rescale_imshow_rgb(darray, vmin, vmax, robust):
# After scaling, downcast to 32-bit float. This substantially reduces
# memory usage after we hand `darray` off to matplotlib.
darray = ((darray.astype("f8") - vmin) / (vmax - vmin)).astype("f4")
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "xarray.ufuncs", PendingDeprecationWarning)
return minimum(maximum(darray, 0), 1)
return np.minimum(np.maximum(darray, 0), 1)


def _update_axes(
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_repr_multiindex(self):
assert expected == repr(self.mda)

@pytest.mark.skipif(
LooseVersion(np.__version__) < "1.15",
LooseVersion(np.__version__) < "1.16",
reason="old versions of numpy have different printing behavior",
)
def test_repr_multiindex_long(self):
Expand Down
25 changes: 20 additions & 5 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,10 @@ def test_squeeze(self, dtype):
"func",
(
method("coarsen", windows={"y": 2}, func=np.mean),
method("quantile", q=[0.25, 0.75]),
pytest.param(
method("quantile", q=[0.25, 0.75]),
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
),
pytest.param(
method("rank", dim="x"),
marks=pytest.mark.xfail(reason="rank not implemented for non-ndarray"),
Expand Down Expand Up @@ -3401,7 +3404,10 @@ def test_stacking_reordering(self, func, dtype):
method("diff", dim="x"),
method("differentiate", coord="x"),
method("integrate", dim="x"),
method("quantile", q=[0.25, 0.75]),
pytest.param(
method("quantile", q=[0.25, 0.75]),
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
),
method("reduce", func=np.sum, dim="x"),
pytest.param(
lambda x: x.dot(x),
Expand Down Expand Up @@ -3491,7 +3497,10 @@ def test_resample(self, dtype):
method("assign_coords", z=(["x"], np.arange(5) * unit_registry.s)),
method("first"),
method("last"),
method("quantile", q=np.array([0.25, 0.5, 0.75]), dim="x"),
pytest.param(
method("quantile", q=[0.25, 0.5, 0.75], dim="x"),
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
),
),
ids=repr,
)
Expand Down Expand Up @@ -4929,7 +4938,10 @@ def test_reindex_like(self, unit, error, dtype):
method("diff", dim="x"),
method("differentiate", coord="x"),
method("integrate", coord="x"),
method("quantile", q=[0.25, 0.75]),
pytest.param(
method("quantile", q=[0.25, 0.75]),
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
),
method("reduce", func=np.sum, dim="x"),
method("map", np.fabs),
),
Expand Down Expand Up @@ -5039,7 +5051,10 @@ def test_resample(self, dtype):
method("assign_coords", v=("x", np.arange(10) * unit_registry.s)),
method("first"),
method("last"),
method("quantile", q=[0.25, 0.5, 0.75], dim="x"),
pytest.param(
method("quantile", q=[0.25, 0.5, 0.75], dim="x"),
marks=pytest.mark.xfail(reason="nanquantile not implemented"),
),
),
ids=repr,
)
Expand Down