Skip to content

Commit

Permalink
Merge branch 'main' into dask-friendly-datetime-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed Jan 27, 2024
2 parents 4b1e978 + e22b475 commit 2f59fbe
Show file tree
Hide file tree
Showing 34 changed files with 445 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
fi
- name: Upload wheel
uses: scientific-python/upload-nightly-action@main
uses: scientific-python/upload-nightly-action@6e9304f7a3a5501c6f98351537493ec898728299 # 0.3.0
with:
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_NIGHTLY }}
artifacts_path: dist
2 changes: 1 addition & 1 deletion HOW_TO_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ upstream https://github.com/pydata/xarray (push)
```sh
pytest
```
8. Check that the ReadTheDocs build is passing on the `main` branch.
8. Check that the [ReadTheDocs build](https://readthedocs.org/projects/xray/) is passing on the `latest` build version (which is built from the `main` branch).
9. Issue the release on GitHub. Click on "Draft a new release" at
<https://github.com/pydata/xarray/releases>. Type in the version number (with a "v")
and paste the release summary in the notes.
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies:
- setuptools
- sparse
- sphinx-autosummary-accessors
- sphinx-book-theme >= 0.3.0
- sphinx-book-theme<=1.0.1
- sphinx-copybutton
- sphinx-design
- sphinx-inline-tabs
Expand Down
1 change: 0 additions & 1 deletion doc/api-hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
core.accessor_dt.DatetimeAccessor.time
core.accessor_dt.DatetimeAccessor.week
core.accessor_dt.DatetimeAccessor.weekday
core.accessor_dt.DatetimeAccessor.weekday_name
core.accessor_dt.DatetimeAccessor.weekofyear
core.accessor_dt.DatetimeAccessor.year

Expand Down
1 change: 0 additions & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ Datetimelike properties
DataArray.dt.nanosecond
DataArray.dt.dayofweek
DataArray.dt.weekday
DataArray.dt.weekday_name
DataArray.dt.dayofyear
DataArray.dt.quarter
DataArray.dt.days_in_month
Expand Down
2 changes: 1 addition & 1 deletion doc/internals/how-to-add-new-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ You can declare the entrypoint in your project configuration like so:

.. code:: toml
[project.entry-points."xarray-backends"]
[project.entry-points."xarray.backends"]
my_engine = "my_package.my_module:MyBackendEntrypoint"
.. tab:: pyproject.toml [Poetry]
Expand Down
64 changes: 58 additions & 6 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,80 @@ What's New
np.random.seed(123456)
.. _whats-new.2024.01.1:
v2024.01.1 (unreleased)
.. _whats-new.2024.02.0:

v2024.02.0 (unreleased)
-----------------------

New Features
~~~~~~~~~~~~

- Xarray now defers to flox's `heuristics <https://flox.readthedocs.io/en/latest/implementation.html#heuristics>`_
to set default `method` for groupby problems. This only applies to ``flox>=0.9``.
By `Deepak Cherian <https://github.com/dcherian>`_.

Breaking changes
~~~~~~~~~~~~~~~~


Deprecations
~~~~~~~~~~~~
- The `dt.weekday_name` parameter wasn't functional on modern pandas versions and has been removed. (:issue:`8610`, :pull:`8664`)
By `Sam Coleman <https://github.com/nameloCmaS>`_.


Bug fixes
~~~~~~~~~

- Fix bug with broadcasting when wrapping array API-compliant classes. (:issue:`8665`, :pull:`8669`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Ensure :py:meth:`DataArray.unstack` works when wrapping array API-compliant classes. (:issue:`8666`, :pull:`8668`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.

Documentation
~~~~~~~~~~~~~

- Fix `variables` arg typo in `Dataset.sortby()` docstring
(:issue:`8663`, :pull:`8670`)
By `Tom Vo <https://github.com/tomvothecoder>`_.

Internal Changes
~~~~~~~~~~~~~~~~


.. _whats-new.2024.01.1:

v2024.01.1 (23 Jan, 2024)
-------------------------

This release is to fix a bug with the rendering of the documentation, but it also includes changes to the handling of pandas frequency strings.

Breaking changes
~~~~~~~~~~~~~~~~

- Following pandas, :py:meth:`infer_freq` will return ``"YE"``, instead of ``"Y"`` (formerly ``"A"``).
This is to be consistent with the deprecation of the latter frequency string in pandas 2.2.
This is a follow up to :pull:`8415` (:issue:`8612`, :pull:`8642`).
By `Mathias Hauser <https://github.com/mathause>`_.

Deprecations
~~~~~~~~~~~~

- Following pandas, the frequency string ``"Y"`` (formerly ``"A"``) is deprecated in
favor of ``"YE"``. These strings are used, for example, in :py:func:`date_range`,
:py:func:`cftime_range`, :py:meth:`DataArray.resample`, and :py:meth:`Dataset.resample`
among others (:issue:`8612`, :pull:`8629`).
By `Mathias Hauser <https://github.com/mathause>`_.

Documentation
~~~~~~~~~~~~~

- Pin ``sphinx-book-theme`` to ``1.0.1`` to fix a rendering issue with the sidebar in the docs. (:issue:`8619`, :pull:`8632`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Fixed documentation where the use of the depreciated pandas frequency string
prevented the documentation from being built. (:pull:`8638`)
By `Sam Coleman <https://github.com/nameloCmaS>`_.

.. _whats-new.2024.01.0:

v2024.01.0 (17 Jan, 2024)
Expand Down Expand Up @@ -7279,10 +7325,16 @@ Breaking changes
- The ``season`` datetime shortcut now returns an array of string labels
such `'DJF'`:

.. ipython:: python
.. code-block:: ipython
In[92]: ds = xray.Dataset({"t": pd.date_range("2000-01-01", periods=12, freq="M")})
ds = xray.Dataset({"t": pd.date_range("2000-01-01", periods=12, freq="M")})
ds["t.season"]
In[93]: ds["t.season"]
Out[93]:
<xarray.DataArray 'season' (t: 12)>
array(['DJF', 'DJF', 'MAM', ..., 'SON', 'SON', 'DJF'], dtype='<U3')
Coordinates:
* t (t) datetime64[ns] 2000-01-31 2000-02-29 ... 2000-11-30 2000-12-31
Previously, it returned numbered seasons 1 through 4.
- We have updated our use of the terms of "coordinates" and "variables". What
Expand Down
30 changes: 20 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ dependencies = [
"pandas>=1.5",
]

[project.optional-dependencies]
accel = ["scipy", "bottleneck", "numbagg", "flox", "opt_einsum"]
complete = ["xarray[accel,io,parallel,viz,dev]"]
dev = [
"hypothesis",
"pre-commit",
"pytest",
"pytest-cov",
"pytest-env",
"pytest-xdist",
"pytest-timeout",
"ruff",
"xarray[complete]",
]
io = ["netCDF4", "h5netcdf", "scipy", 'pydap; python_version<"3.10"', "zarr", "fsspec", "cftime", "pooch"]
parallel = ["dask[complete]"]
viz = ["matplotlib", "seaborn", "nc-time-axis"]

[project.urls]
Documentation = "https://docs.xarray.dev"
SciPy2015-talk = "https://www.youtube.com/watch?v=X0pAhJgySxk"
Expand All @@ -38,13 +56,6 @@ source-code = "https://github.com/pydata/xarray"
[project.entry-points."xarray.chunkmanagers"]
dask = "xarray.core.daskmanager:DaskManager"

[project.optional-dependencies]
accel = ["scipy", "bottleneck", "numbagg", "flox", "opt_einsum"]
complete = ["xarray[accel,io,parallel,viz]"]
io = ["netCDF4", "h5netcdf", "scipy", 'pydap; python_version<"3.10"', "zarr", "fsspec", "cftime", "pooch"]
parallel = ["dask[complete]"]
viz = ["matplotlib", "seaborn", "nc-time-axis"]

[build-system]
build-backend = "setuptools.build_meta"
requires = [
Expand Down Expand Up @@ -227,8 +238,7 @@ reportMissingTypeStubs = false

[tool.ruff]
builtins = ["ellipsis"]
exclude = [
".eggs",
extend-exclude = [
"doc",
"_typed_ops.pyi",
]
Expand Down Expand Up @@ -274,5 +284,5 @@ test = "pytest"

[tool.repo-review]
ignore = [
"PP308" # This option creates a large amount of log lines.
"PP308", # This option creates a large amount of log lines.
]
2 changes: 1 addition & 1 deletion xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ def save_mfdataset(
>>> ds = xr.Dataset(
... {"a": ("time", np.linspace(0, 1, 48))},
... coords={"time": pd.date_range("2010-01-01", freq="M", periods=48)},
... coords={"time": pd.date_range("2010-01-01", freq="ME", periods=48)},
... )
>>> ds
<xarray.Dataset>
Expand Down
43 changes: 22 additions & 21 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def rollback(self, date):


class YearEnd(YearOffset):
_freq = "Y"
_freq = "YE"
_day_option = "end"
_default_month = 12

Expand Down Expand Up @@ -669,6 +669,7 @@ def _generate_anchored_offsets(base_freq, offset):
"A": YearEnd,
"AS": YearBegin,
"Y": YearEnd,
"YE": YearEnd,
"YS": YearBegin,
"Q": partial(QuarterEnd, month=12),
"QE": partial(QuarterEnd, month=12),
Expand All @@ -691,6 +692,7 @@ def _generate_anchored_offsets(base_freq, offset):
**_generate_anchored_offsets("A", YearEnd),
**_generate_anchored_offsets("YS", YearBegin),
**_generate_anchored_offsets("Y", YearEnd),
**_generate_anchored_offsets("YE", YearEnd),
**_generate_anchored_offsets("QS", QuarterBegin),
**_generate_anchored_offsets("Q", QuarterEnd),
**_generate_anchored_offsets("QE", QuarterEnd),
Expand All @@ -716,7 +718,8 @@ def _generate_anchored_deprecated_frequencies(deprecated, recommended):


_DEPRECATED_FREQUENICES = {
"A": "Y",
"A": "YE",
"Y": "YE",
"AS": "YS",
"Q": "QE",
"M": "ME",
Expand All @@ -725,7 +728,8 @@ def _generate_anchored_deprecated_frequencies(deprecated, recommended):
"S": "s",
"L": "ms",
"U": "us",
**_generate_anchored_deprecated_frequencies("A", "Y"),
**_generate_anchored_deprecated_frequencies("A", "YE"),
**_generate_anchored_deprecated_frequencies("Y", "YE"),
**_generate_anchored_deprecated_frequencies("AS", "YS"),
**_generate_anchored_deprecated_frequencies("Q", "QE"),
}
Expand Down Expand Up @@ -979,7 +983,7 @@ def cftime_range(
+--------+--------------------------+
| Alias | Description |
+========+==========================+
| Y | Year-end frequency |
| YE | Year-end frequency |
+--------+--------------------------+
| YS | Year-start frequency |
+--------+--------------------------+
Expand Down Expand Up @@ -1009,29 +1013,29 @@ def cftime_range(
+------------+--------------------------------------------------------------------+
| Alias | Description |
+============+====================================================================+
| Y(S)-JAN | Annual frequency, anchored at the end (or beginning) of January |
| Y(E,S)-JAN | Annual frequency, anchored at the (end, beginning) of January |
+------------+--------------------------------------------------------------------+
| Y(S)-FEB | Annual frequency, anchored at the end (or beginning) of February |
| Y(E,S)-FEB | Annual frequency, anchored at the (end, beginning) of February |
+------------+--------------------------------------------------------------------+
| Y(S)-MAR | Annual frequency, anchored at the end (or beginning) of March |
| Y(E,S)-MAR | Annual frequency, anchored at the (end, beginning) of March |
+------------+--------------------------------------------------------------------+
| Y(S)-APR | Annual frequency, anchored at the end (or beginning) of April |
| Y(E,S)-APR | Annual frequency, anchored at the (end, beginning) of April |
+------------+--------------------------------------------------------------------+
| Y(S)-MAY | Annual frequency, anchored at the end (or beginning) of May |
| Y(E,S)-MAY | Annual frequency, anchored at the (end, beginning) of May |
+------------+--------------------------------------------------------------------+
| Y(S)-JUN | Annual frequency, anchored at the end (or beginning) of June |
| Y(E,S)-JUN | Annual frequency, anchored at the (end, beginning) of June |
+------------+--------------------------------------------------------------------+
| Y(S)-JUL | Annual frequency, anchored at the end (or beginning) of July |
| Y(E,S)-JUL | Annual frequency, anchored at the (end, beginning) of July |
+------------+--------------------------------------------------------------------+
| Y(S)-AUG | Annual frequency, anchored at the end (or beginning) of August |
| Y(E,S)-AUG | Annual frequency, anchored at the (end, beginning) of August |
+------------+--------------------------------------------------------------------+
| Y(S)-SEP | Annual frequency, anchored at the end (or beginning) of September |
| Y(E,S)-SEP | Annual frequency, anchored at the (end, beginning) of September |
+------------+--------------------------------------------------------------------+
| Y(S)-OCT | Annual frequency, anchored at the end (or beginning) of October |
| Y(E,S)-OCT | Annual frequency, anchored at the (end, beginning) of October |
+------------+--------------------------------------------------------------------+
| Y(S)-NOV | Annual frequency, anchored at the end (or beginning) of November |
| Y(E,S)-NOV | Annual frequency, anchored at the (end, beginning) of November |
+------------+--------------------------------------------------------------------+
| Y(S)-DEC | Annual frequency, anchored at the end (or beginning) of December |
| Y(E,S)-DEC | Annual frequency, anchored at the (end, beginning) of December |
+------------+--------------------------------------------------------------------+
| Q(E,S)-JAN | Quarter frequency, anchored at the (end, beginning) of January |
+------------+--------------------------------------------------------------------+
Expand Down Expand Up @@ -1311,11 +1315,8 @@ def date_range_like(source, calendar, use_cftime=None):
freq = freq.replace("QE", "Q")
elif isinstance(freq_as_offset, YearBegin) and "YS" in freq:
freq = freq.replace("YS", "AS")
elif isinstance(freq_as_offset, YearEnd) and "Y-" in freq:
# Check for and replace "Y-" instead of just "Y" to prevent
# corrupting anchored offsets that contain "Y" in the month
# abbreviation, e.g. "Y-MAY" -> "A-MAY".
freq = freq.replace("Y-", "A-")
elif isinstance(freq_as_offset, YearEnd) and "YE" in freq:
freq = freq.replace("YE", "A")

use_cftime = _should_cftime_be_used(source, calendar, use_cftime)

Expand Down
2 changes: 1 addition & 1 deletion xarray/coding/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _get_annual_rule(self):
if len(np.unique(self.index.month)) > 1:
return None

return {"cs": "YS", "ce": "Y"}.get(month_anchor_check(self.index))
return {"cs": "YS", "ce": "YE"}.get(month_anchor_check(self.index))

def _get_quartely_rule(self):
if len(self.month_deltas) > 1:
Expand Down
Loading

0 comments on commit 2f59fbe

Please sign in to comment.