Skip to content

Commit 3c3e111

Browse files
authored
Refactor modules from core into xarray.computation (pydata#10132)
1 parent b085d8b commit 3c3e111

27 files changed

+136
-120
lines changed

doc/api-hidden.rst

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828
core.coordinates.DatasetCoordinates.equals
2929
core.coordinates.DatasetCoordinates.identical
3030

31-
core.rolling.DatasetCoarsen.boundary
32-
core.rolling.DatasetCoarsen.coord_func
33-
core.rolling.DatasetCoarsen.obj
34-
core.rolling.DatasetCoarsen.side
35-
core.rolling.DatasetCoarsen.trim_excess
36-
core.rolling.DatasetCoarsen.windows
37-
38-
core.rolling.DatasetRolling.center
39-
core.rolling.DatasetRolling.dim
40-
core.rolling.DatasetRolling.min_periods
41-
core.rolling.DatasetRolling.obj
42-
core.rolling.DatasetRolling.rollings
43-
core.rolling.DatasetRolling.window
44-
45-
core.weighted.DatasetWeighted.obj
46-
core.weighted.DatasetWeighted.weights
31+
computation.rolling.DatasetCoarsen.boundary
32+
computation.rolling.DatasetCoarsen.coord_func
33+
computation.rolling.DatasetCoarsen.obj
34+
computation.rolling.DatasetCoarsen.side
35+
computation.rolling.DatasetCoarsen.trim_excess
36+
computation.rolling.DatasetCoarsen.windows
37+
38+
computation.rolling.DatasetRolling.center
39+
computation.rolling.DatasetRolling.dim
40+
computation.rolling.DatasetRolling.min_periods
41+
computation.rolling.DatasetRolling.obj
42+
computation.rolling.DatasetRolling.rollings
43+
computation.rolling.DatasetRolling.window
44+
45+
computation.weighted.DatasetWeighted.obj
46+
computation.weighted.DatasetWeighted.weights
4747

4848
Dataset.load_store
4949
Dataset.dump_to_store
@@ -70,22 +70,22 @@
7070
core.coordinates.DataArrayCoordinates.equals
7171
core.coordinates.DataArrayCoordinates.identical
7272

73-
core.rolling.DataArrayCoarsen.boundary
74-
core.rolling.DataArrayCoarsen.coord_func
75-
core.rolling.DataArrayCoarsen.obj
76-
core.rolling.DataArrayCoarsen.side
77-
core.rolling.DataArrayCoarsen.trim_excess
78-
core.rolling.DataArrayCoarsen.windows
79-
80-
core.rolling.DataArrayRolling.center
81-
core.rolling.DataArrayRolling.dim
82-
core.rolling.DataArrayRolling.min_periods
83-
core.rolling.DataArrayRolling.obj
84-
core.rolling.DataArrayRolling.window
85-
core.rolling.DataArrayRolling.window_labels
86-
87-
core.weighted.DataArrayWeighted.obj
88-
core.weighted.DataArrayWeighted.weights
73+
computation.rolling.DataArrayCoarsen.boundary
74+
computation.rolling.DataArrayCoarsen.coord_func
75+
computation.rolling.DataArrayCoarsen.obj
76+
computation.rolling.DataArrayCoarsen.side
77+
computation.rolling.DataArrayCoarsen.trim_excess
78+
computation.rolling.DataArrayCoarsen.windows
79+
80+
computation.rolling.DataArrayRolling.center
81+
computation.rolling.DataArrayRolling.dim
82+
computation.rolling.DataArrayRolling.min_periods
83+
computation.rolling.DataArrayRolling.obj
84+
computation.rolling.DataArrayRolling.window
85+
computation.rolling.DataArrayRolling.window_labels
86+
87+
computation.weighted.DataArrayWeighted.obj
88+
computation.weighted.DataArrayWeighted.weights
8989

9090
core.coordinates.DataTreeCoordinates.get
9191
core.coordinates.DataTreeCoordinates.items

doc/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ Grouper Objects
13341334
Rolling objects
13351335
===============
13361336

1337-
.. currentmodule:: xarray.core.rolling
1337+
.. currentmodule:: xarray.computation.rolling
13381338

13391339
Dataset
13401340
-------
@@ -1427,7 +1427,7 @@ DataArray
14271427
Exponential rolling objects
14281428
===========================
14291429

1430-
.. currentmodule:: xarray.core.rolling_exp
1430+
.. currentmodule:: xarray.computation.rolling_exp
14311431

14321432
.. autosummary::
14331433
:toctree: generated/
@@ -1439,7 +1439,7 @@ Exponential rolling objects
14391439
Weighted objects
14401440
================
14411441

1442-
.. currentmodule:: xarray.core.weighted
1442+
.. currentmodule:: xarray.computation.weighted
14431443

14441444
Dataset
14451445
-------

doc/user-guide/reshaping.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Reshaping via coarsen
305305

306306
Whilst :py:class:`~xarray.DataArray.coarsen` is normally used for reducing your data's resolution by applying a reduction function
307307
(see the :ref:`page on computation<compute.coarsen>`),
308-
it can also be used to reorganise your data without applying a computation via :py:meth:`~xarray.core.rolling.DataArrayCoarsen.construct`.
308+
it can also be used to reorganise your data without applying a computation via :py:meth:`~xarray.computation.rolling.DataArrayCoarsen.construct`.
309309

310310
Taking our example tutorial air temperature dataset over the Northern US
311311

@@ -324,7 +324,7 @@ Taking our example tutorial air temperature dataset over the Northern US
324324
@savefig pre_coarsening.png
325325
air.isel(time=0).plot(x="lon", y="lat")
326326
327-
we can split this up into sub-regions of size ``(9, 18)`` points using :py:meth:`~xarray.core.rolling.DataArrayCoarsen.construct`:
327+
we can split this up into sub-regions of size ``(9, 18)`` points using :py:meth:`~xarray.computation.rolling.DataArrayCoarsen.construct`:
328328

329329
.. ipython:: python
330330

doc/whats-new.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ Bug fixes
14731473
special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar`
14741474
(:issue:`7928`, :pull:`8084`).
14751475
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
1476-
- Fix :py:meth:`~core.rolling.DatasetRolling.construct` with stride on Datasets without indexes.
1476+
- Fix :py:meth:`~computation.rolling.DatasetRolling.construct` with stride on Datasets without indexes.
14771477
(:issue:`7021`, :pull:`7578`).
14781478
By `Amrest Chinkamol <https://github.com/p4perf4ce>`_ and `Michael Niklas <https://github.com/headtr1ck>`_.
14791479
- Calling plot with kwargs ``col``, ``row`` or ``hue`` no longer squeezes dimensions passed via these arguments
@@ -2488,8 +2488,8 @@ New Features
24882488

24892489
- The ``zarr`` backend is now able to read NCZarr.
24902490
By `Mattia Almansi <https://github.com/malmans2>`_.
2491-
- Add a weighted ``quantile`` method to :py:class:`~core.weighted.DatasetWeighted` and
2492-
:py:class:`~core.weighted.DataArrayWeighted` (:pull:`6059`).
2491+
- Add a weighted ``quantile`` method to :py:class:`.computation.weighted.DatasetWeighted` and
2492+
:py:class:`~computation.weighted.DataArrayWeighted` (:pull:`6059`).
24932493
By `Christian Jauvin <https://github.com/cjauvin>`_ and `David Huard <https://github.com/huard>`_.
24942494
- Add a ``create_index=True`` parameter to :py:meth:`Dataset.stack` and
24952495
:py:meth:`DataArray.stack` so that the creation of multi-indexes is optional
@@ -2871,7 +2871,7 @@ Thomas Nicholas, Tomas Chor, Tom Augspurger, Victor Negîrneac, Zachary Blackwoo
28712871

28722872
New Features
28732873
~~~~~~~~~~~~
2874-
- Add ``std``, ``var``, ``sum_of_squares`` to :py:class:`~core.weighted.DatasetWeighted` and :py:class:`~core.weighted.DataArrayWeighted`.
2874+
- Add ``std``, ``var``, ``sum_of_squares`` to :py:class:`~computation.weighted.DatasetWeighted` and :py:class:`~computation.weighted.DataArrayWeighted`.
28752875
By `Christian Jauvin <https://github.com/cjauvin>`_.
28762876
- Added a :py:func:`get_options` method to xarray's root namespace (:issue:`5698`, :pull:`5716`)
28772877
By `Pushkar Kopparla <https://github.com/pkopparla>`_.
@@ -3507,7 +3507,7 @@ New Features
35073507
By `Justus Magin <https://github.com/keewis>`_.
35083508
- Allow installing from git archives (:pull:`4897`).
35093509
By `Justus Magin <https://github.com/keewis>`_.
3510-
- :py:class:`~core.rolling.DataArrayCoarsen` and :py:class:`~core.rolling.DatasetCoarsen`
3510+
- :py:class:`~computation.rolling.DataArrayCoarsen` and :py:class:`~computation.rolling.DatasetCoarsen`
35113511
now implement a ``reduce`` method, enabling coarsening operations with custom
35123512
reduction functions (:issue:`3741`, :pull:`4939`).
35133513
By `Spencer Clark <https://github.com/spencerkclark>`_.
@@ -4352,8 +4352,8 @@ New Features
43524352
- :py:meth:`Dataset.quantile`, :py:meth:`DataArray.quantile` and ``GroupBy.quantile``
43534353
now work with dask Variables.
43544354
By `Deepak Cherian <https://github.com/dcherian>`_.
4355-
- Added the ``count`` reduction method to both :py:class:`~core.rolling.DatasetCoarsen`
4356-
and :py:class:`~core.rolling.DataArrayCoarsen` objects. (:pull:`3500`)
4355+
- Added the ``count`` reduction method to both :py:class:`~computation.rolling.DatasetCoarsen`
4356+
and :py:class:`~computation.rolling.DataArrayCoarsen` objects. (:pull:`3500`)
43574357
By `Deepak Cherian <https://github.com/dcherian>`_
43584358
- Add ``meta`` kwarg to :py:func:`~xarray.apply_ufunc`;
43594359
this is passed on to :py:func:`dask.array.blockwise`. (:pull:`3660`)
@@ -4705,7 +4705,7 @@ Bug fixes
47054705
- Fix error in concatenating unlabeled dimensions (:pull:`3362`).
47064706
By `Deepak Cherian <https://github.com/dcherian>`_.
47074707
- Warn if the ``dim`` kwarg is passed to rolling operations. This is redundant since a dimension is
4708-
specified when the :py:class:`~core.rolling.DatasetRolling` or :py:class:`~core.rolling.DataArrayRolling` object is created.
4708+
specified when the :py:class:`~computation.rolling.DatasetRolling` or :py:class:`~computation.rolling.DataArrayRolling` object is created.
47094709
(:pull:`3362`). By `Deepak Cherian <https://github.com/dcherian>`_.
47104710

47114711
Documentation
@@ -5936,7 +5936,7 @@ Enhancements
59365936
supplied list, returning a bool array. See :ref:`selecting values with isin`
59375937
for full details. Similar to the ``np.isin`` function.
59385938
By `Maximilian Roos <https://github.com/max-sixty>`_.
5939-
- Some speed improvement to construct :py:class:`~xarray.core.rolling.DataArrayRolling`
5939+
- Some speed improvement to construct :py:class:`~xarray.computation.rolling.DataArrayRolling`
59405940
object (:issue:`1993`)
59415941
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
59425942
- Handle variables with different values for ``missing_value`` and
@@ -6016,8 +6016,8 @@ Enhancements
60166016
NumPy. By `Stephan Hoyer <https://github.com/shoyer>`_.
60176017

60186018
- Improve :py:func:`~xarray.DataArray.rolling` logic.
6019-
:py:func:`~xarray.core.rolling.DataArrayRolling` object now supports
6020-
:py:func:`~xarray.core.rolling.DataArrayRolling.construct` method that returns a view
6019+
:py:func:`~xarray.computation.rolling.DataArrayRolling` object now supports
6020+
:py:func:`~xarray.computation.rolling.DataArrayRolling.construct` method that returns a view
60216021
of the DataArray / Dataset object with the rolling-window dimension added
60226022
to the last axis. This enables more flexible operation, such as strided
60236023
rolling, windowed rolling, ND-rolling, short-time FFT and convolution.
@@ -6791,7 +6791,7 @@ Enhancements
67916791
By `Stephan Hoyer <https://github.com/shoyer>`_ and
67926792
`Phillip J. Wolfram <https://github.com/pwolfram>`_.
67936793

6794-
- New aggregation on rolling objects :py:meth:`~core.rolling.DataArrayRolling.count`
6794+
- New aggregation on rolling objects :py:meth:`~computation.rolling.DataArrayRolling.count`
67956795
which providing a rolling count of valid values (:issue:`1138`).
67966796

67976797
Bug fixes

pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ fallback_version = "9999"
102102
[tool.coverage.run]
103103
omit = [
104104
"*/xarray/tests/*",
105-
"*/xarray/core/dask_array_compat.py",
106-
"*/xarray/core/npcompat.py",
107-
"*/xarray/core/pdcompat.py",
108-
"*/xarray/core/pycompat.py",
105+
"*/xarray/compat/dask_array_compat.py",
106+
"*/xarray/compat/npcompat.py",
107+
"*/xarray/compat/pdcompat.py",
108+
"*/xarray/namedarray/pycompat.py",
109109
"*/xarray/core/types.py",
110110
]
111111
source = ["xarray"]
@@ -170,8 +170,7 @@ module = [
170170
"xarray.core.accessor_dt",
171171
"xarray.core.accessor_str",
172172
"xarray.core.alignment",
173-
"xarray.core.computation",
174-
"xarray.core.rolling_exp",
173+
"xarray.computation.*",
175174
"xarray.indexes.*",
176175
"xarray.tests.*",
177176
]

xarray/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
from xarray.coding.cftime_offsets import cftime_range, date_range, date_range_like
1616
from xarray.coding.cftimeindex import CFTimeIndex
1717
from xarray.coding.frequencies import infer_freq
18-
from xarray.conventions import SerializationWarning, decode_cf
19-
from xarray.core.alignment import align, broadcast
20-
from xarray.core.combine import combine_by_coords, combine_nested
21-
from xarray.core.common import ALL_DIMS, full_like, ones_like, zeros_like
22-
from xarray.core.computation import (
18+
from xarray.computation.computation import (
2319
apply_ufunc,
2420
corr,
2521
cov,
@@ -29,6 +25,10 @@
2925
unify_chunks,
3026
where,
3127
)
28+
from xarray.conventions import SerializationWarning, decode_cf
29+
from xarray.core.alignment import align, broadcast
30+
from xarray.core.combine import combine_by_coords, combine_nested
31+
from xarray.core.common import ALL_DIMS, full_like, ones_like, zeros_like
3232
from xarray.core.concat import concat
3333
from xarray.core.coordinates import Coordinates
3434
from xarray.core.dataarray import DataArray

xarray/coding/calendar_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
_should_cftime_be_used,
1010
convert_times,
1111
)
12+
from xarray.computation.computation import apply_ufunc
1213
from xarray.core.common import (
1314
_contains_datetime_like_objects,
1415
full_like,
1516
is_np_datetime_like,
1617
)
17-
from xarray.core.computation import apply_ufunc
1818

1919
try:
2020
import cftime

xarray/computation/__init__.py

Whitespace-only changes.

xarray/core/arithmetic.py renamed to xarray/computation/arithmetic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import numpy as np
88

9+
from xarray.computation.ops import IncludeNumpySameMethods, IncludeReduceMethods
10+
911
# _typed_ops.py is a generated file
1012
from xarray.core._typed_ops import (
1113
DataArrayGroupByOpsMixin,
@@ -15,7 +17,6 @@
1517
VariableOpsMixin,
1618
)
1719
from xarray.core.common import ImplementsArrayReduce, ImplementsDatasetReduce
18-
from xarray.core.ops import IncludeNumpySameMethods, IncludeReduceMethods
1920
from xarray.core.options import OPTIONS, _get_keep_attrs
2021
from xarray.namedarray.utils import is_duck_array
2122

@@ -29,7 +30,7 @@ class SupportsArithmetic:
2930
__slots__ = ()
3031

3132
# TODO: implement special methods for arithmetic here rather than injecting
32-
# them in xarray/core/ops.py. Ideally, do so by inheriting from
33+
# them in xarray/computation/ops.py. Ideally, do so by inheriting from
3334
# numpy.lib.mixins.NDArrayOperatorsMixin.
3435

3536
# TODO: allow extending this with some sort of registration system
@@ -41,7 +42,7 @@ class SupportsArithmetic:
4142
)
4243

4344
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
44-
from xarray.core.computation import apply_ufunc
45+
from xarray.computation.computation import apply_ufunc
4546

4647
# See the docstring example for numpy.lib.mixins.NDArrayOperatorsMixin.
4748
out = kwargs.get("out", ())

xarray/core/computation.py renamed to xarray/computation/computation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""
22
Functions for applying functions that act on arrays to xarray's labeled data.
3+
4+
NOTE: This module is currently large and contains various computational functionality.
5+
The long-term plan is to break it down into more focused submodules.
36
"""
47

58
from __future__ import annotations

0 commit comments

Comments
 (0)