Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ repos:
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.11
rev: v0.13.3
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/keewis/blackdoc
rev: v0.4.1
rev: v0.4.3
hooks:
- id: blackdoc
exclude: "generate_aggregations.py"
Expand All @@ -41,7 +41,7 @@ repos:
- id: prettier
args: [--cache-location=.prettier_cache/cache]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
rev: v1.18.2
hooks:
- id: mypy
# Copied from setup.cfg
Expand Down Expand Up @@ -73,6 +73,6 @@ repos:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]
- repo: https://github.com/adhtruong/mirrors-typos
rev: v1.35.6
rev: v1.37.2
hooks:
- id: typos
6 changes: 3 additions & 3 deletions xarray/computation/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def _calc_idxminmax(
array = array.where(~allna, 0)

# This will run argmin or argmax.
indx = func(array, dim=dim, axis=None, keep_attrs=keep_attrs, skipna=skipna)
index = func(array, dim=dim, axis=None, keep_attrs=keep_attrs, skipna=skipna)

# Handle chunked arrays (e.g. dask).
coord = array[dim]._variable.to_base_variable()
Expand All @@ -943,13 +943,13 @@ def _calc_idxminmax(
else:
coord = coord.copy(data=to_like_array(array[dim].data, array.data))

res = indx._replace(coord[(indx.variable,)]).rename(dim)
res = index._replace(coord[(index.variable,)]).rename(dim)

if skipna or (skipna is None and array.dtype.kind in na_dtypes):
# Put the NaN values back in after removing them
res = res.where(~allna, fill_value)

# Copy attributes from argmin/argmax, if any
res.attrs = indx.attrs
res.attrs = index.attrs

return res
38 changes: 19 additions & 19 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,17 +1402,17 @@ def test_asi8_empty_cftimeindex():

@requires_cftime
def test_infer_freq_valid_types(time_unit: PDDatetimeUnitOptions) -> None:
cf_indx = xr.date_range("2000-01-01", periods=3, freq="D", use_cftime=True)
assert xr.infer_freq(cf_indx) == "D"
assert xr.infer_freq(xr.DataArray(cf_indx)) == "D"
cf_index = xr.date_range("2000-01-01", periods=3, freq="D", use_cftime=True)
assert xr.infer_freq(cf_index) == "D"
assert xr.infer_freq(xr.DataArray(cf_index)) == "D"

pd_indx = pd.date_range("2000-01-01", periods=3, freq="D").as_unit(time_unit)
assert xr.infer_freq(pd_indx) == "D"
assert xr.infer_freq(xr.DataArray(pd_indx)) == "D"
pd_index = pd.date_range("2000-01-01", periods=3, freq="D").as_unit(time_unit)
assert xr.infer_freq(pd_index) == "D"
assert xr.infer_freq(xr.DataArray(pd_index)) == "D"

pd_td_indx = pd.timedelta_range(start="1D", periods=3, freq="D").as_unit(time_unit)
assert xr.infer_freq(pd_td_indx) == "D"
assert xr.infer_freq(xr.DataArray(pd_td_indx)) == "D"
pd_td_index = pd.timedelta_range(start="1D", periods=3, freq="D").as_unit(time_unit)
assert xr.infer_freq(pd_td_index) == "D"
assert xr.infer_freq(xr.DataArray(pd_td_index)) == "D"


@requires_cftime
Expand All @@ -1421,27 +1421,27 @@ def test_infer_freq_invalid_inputs():
with pytest.raises(ValueError, match="must contain datetime-like objects"):
xr.infer_freq(xr.DataArray([0, 1, 2]))

indx = xr.date_range("1990-02-03", periods=4, freq="MS", use_cftime=True)
index = xr.date_range("1990-02-03", periods=4, freq="MS", use_cftime=True)
# 2D DataArray
with pytest.raises(ValueError, match="must be 1D"):
xr.infer_freq(xr.DataArray([indx, indx]))
xr.infer_freq(xr.DataArray([index, index]))

# CFTimeIndex too short
with pytest.raises(ValueError, match="Need at least 3 dates to infer frequency"):
xr.infer_freq(indx[:2])
xr.infer_freq(index[:2])

# Non-monotonic input
assert xr.infer_freq(indx[np.array([0, 2, 1, 3])]) is None
assert xr.infer_freq(index[np.array([0, 2, 1, 3])]) is None

# Non-unique input
assert xr.infer_freq(indx[np.array([0, 1, 1, 2])]) is None
assert xr.infer_freq(index[np.array([0, 1, 1, 2])]) is None

# No unique frequency (here 1st step is MS, second is 2MS)
assert xr.infer_freq(indx[np.array([0, 1, 3])]) is None
assert xr.infer_freq(index[np.array([0, 1, 3])]) is None

# Same, but for QS
indx = xr.date_range("1990-02-03", periods=4, freq="QS", use_cftime=True)
assert xr.infer_freq(indx[np.array([0, 1, 3])]) is None
index = xr.date_range("1990-02-03", periods=4, freq="QS", use_cftime=True)
assert xr.infer_freq(index[np.array([0, 1, 3])]) is None


@requires_cftime
Expand All @@ -1465,10 +1465,10 @@ def test_infer_freq_invalid_inputs():
)
@pytest.mark.parametrize("calendar", _CFTIME_CALENDARS)
def test_infer_freq(freq, calendar):
indx = xr.date_range(
index = xr.date_range(
"2000-01-01", periods=3, freq=freq, calendar=calendar, use_cftime=True
)
out = xr.infer_freq(indx)
out = xr.infer_freq(index)
assert out == freq


Expand Down
Loading