Skip to content

Commit d644607

Browse files
TomNicholaspre-commit-ci[bot]andersy005
authored
Move parallelcompat and chunkmanagers to NamedArray (#8319)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Anderson Banihirwe <13301940+andersy005@users.noreply.github.com> Co-authored-by: Anderson Banihirwe <axbanihirwe@ualr.edu>
1 parent 3d490ec commit d644607

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+566
-562
lines changed

doc/internals/chunked-arrays.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,44 @@ The implementation of these functions is specific to the type of arrays passed t
3535
whereas :py:class:`cubed.Array` objects must be processed by :py:func:`cubed.map_blocks`.
3636

3737
In order to use the correct implementation of a core operation for the array type encountered, xarray dispatches to the
38-
corresponding subclass of :py:class:`~xarray.core.parallelcompat.ChunkManagerEntrypoint`,
38+
corresponding subclass of :py:class:`~xarray.namedarray.parallelcompat.ChunkManagerEntrypoint`,
3939
also known as a "Chunk Manager". Therefore **a full list of the operations that need to be defined is set by the
40-
API of the** :py:class:`~xarray.core.parallelcompat.ChunkManagerEntrypoint` **abstract base class**. Note that chunked array
40+
API of the** :py:class:`~xarray.namedarray.parallelcompat.ChunkManagerEntrypoint` **abstract base class**. Note that chunked array
4141
methods are also currently dispatched using this class.
4242

4343
Chunked array creation is also handled by this class. As chunked array objects have a one-to-one correspondence with
4444
in-memory numpy arrays, it should be possible to create a chunked array from a numpy array by passing the desired
45-
chunking pattern to an implementation of :py:class:`~xarray.core.parallelcompat.ChunkManagerEntrypoint.from_array``.
45+
chunking pattern to an implementation of :py:class:`~xarray.namedarray.parallelcompat.ChunkManagerEntrypoint.from_array``.
4646

4747
.. note::
4848

49-
The :py:class:`~xarray.core.parallelcompat.ChunkManagerEntrypoint` abstract base class is mostly just acting as a
49+
The :py:class:`~xarray.namedarray.parallelcompat.ChunkManagerEntrypoint` abstract base class is mostly just acting as a
5050
namespace for containing the chunked-aware function primitives. Ideally in the future we would have an API standard
5151
for chunked array types which codified this structure, making the entrypoint system unnecessary.
5252

53-
.. currentmodule:: xarray.core.parallelcompat
53+
.. currentmodule:: xarray.namedarray.parallelcompat
5454

55-
.. autoclass:: xarray.core.parallelcompat.ChunkManagerEntrypoint
55+
.. autoclass:: xarray.namedarray.parallelcompat.ChunkManagerEntrypoint
5656
:members:
5757

5858
Registering a new ChunkManagerEntrypoint subclass
5959
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6060

6161
Rather than hard-coding various chunk managers to deal with specific chunked array implementations, xarray uses an
6262
entrypoint system to allow developers of new chunked array implementations to register their corresponding subclass of
63-
:py:class:`~xarray.core.parallelcompat.ChunkManagerEntrypoint`.
63+
:py:class:`~xarray.namedarray.parallelcompat.ChunkManagerEntrypoint`.
6464

6565

6666
To register a new entrypoint you need to add an entry to the ``setup.cfg`` like this::
6767

6868
[options.entry_points]
6969
xarray.chunkmanagers =
70-
dask = xarray.core.daskmanager:DaskManager
70+
dask = xarray.namedarray.daskmanager:DaskManager
7171

7272
See also `cubed-xarray <https://github.com/xarray-contrib/cubed-xarray>`_ for another example.
7373

7474
To check that the entrypoint has worked correctly, you may find it useful to display the available chunkmanagers using
75-
the internal function :py:func:`~xarray.core.parallelcompat.list_chunkmanagers`.
75+
the internal function :py:func:`~xarray.namedarray.parallelcompat.list_chunkmanagers`.
7676

7777
.. autofunction:: list_chunkmanagers
7878

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ Internal Changes
8888
when the data isn't datetime-like. (:issue:`8718`, :pull:`8724`)
8989
By `Maximilian Roos <https://github.com/max-sixty>`_.
9090

91+
- Move `parallelcompat` and `chunk managers` modules from `xarray/core` to `xarray/namedarray`. (:pull:`8319`)
92+
By `Tom Nicholas <https://github.com/TomNicholas>`_ and `Anderson Banihirwe <https://github.com/andersy005>`_.
93+
9194
.. _whats-new.2024.01.1:
9295

9396
v2024.01.1 (23 Jan, 2024)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ issue-tracker = "https://github.com/pydata/xarray/issues"
5454
source-code = "https://github.com/pydata/xarray"
5555

5656
[project.entry-points."xarray.chunkmanagers"]
57-
dask = "xarray.core.daskmanager:DaskManager"
57+
dask = "xarray.namedarray.daskmanager:DaskManager"
5858

5959
[build-system]
6060
build-backend = "setuptools.build_meta"

xarray/backends/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
_nested_combine,
3535
combine_by_coords,
3636
)
37-
from xarray.core.daskmanager import DaskManager
3837
from xarray.core.dataarray import DataArray
3938
from xarray.core.dataset import Dataset, _get_chunk, _maybe_chunk
4039
from xarray.core.indexes import Index
41-
from xarray.core.parallelcompat import guess_chunkmanager
4240
from xarray.core.types import ZarrWriteModes
4341
from xarray.core.utils import is_remote_uri
42+
from xarray.namedarray.daskmanager import DaskManager
43+
from xarray.namedarray.parallelcompat import guess_chunkmanager
4444

4545
if TYPE_CHECKING:
4646
try:

xarray/backends/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from xarray.conventions import cf_encoder
1414
from xarray.core import indexing
15-
from xarray.core.parallelcompat import get_chunked_array_type
16-
from xarray.core.pycompat import is_chunked_array
1715
from xarray.core.utils import FrozenDict, NdimSizeLenMixin, is_remote_uri
16+
from xarray.namedarray.parallelcompat import get_chunked_array_type
17+
from xarray.namedarray.pycompat import is_chunked_array
1818

1919
if TYPE_CHECKING:
2020
from io import BufferedIOBase

xarray/backends/pydap_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
)
1515
from xarray.backends.store import StoreBackendEntrypoint
1616
from xarray.core import indexing
17-
from xarray.core.pycompat import integer_types
1817
from xarray.core.utils import (
1918
Frozen,
2019
FrozenDict,
@@ -23,6 +22,7 @@
2322
is_remote_uri,
2423
)
2524
from xarray.core.variable import Variable
25+
from xarray.namedarray.pycompat import integer_types
2626

2727
if TYPE_CHECKING:
2828
import os

xarray/backends/zarr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
)
2020
from xarray.backends.store import StoreBackendEntrypoint
2121
from xarray.core import indexing
22-
from xarray.core.parallelcompat import guess_chunkmanager
23-
from xarray.core.pycompat import integer_types
2422
from xarray.core.types import ZarrWriteModes
2523
from xarray.core.utils import (
2624
FrozenDict,
2725
HiddenKeyDict,
2826
close_on_error,
2927
)
3028
from xarray.core.variable import Variable
29+
from xarray.namedarray.parallelcompat import guess_chunkmanager
30+
from xarray.namedarray.pycompat import integer_types
3131

3232
if TYPE_CHECKING:
3333
from io import BufferedIOBase

xarray/coding/strings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
unpack_for_encoding,
1616
)
1717
from xarray.core import indexing
18-
from xarray.core.parallelcompat import get_chunked_array_type, is_chunked_array
1918
from xarray.core.variable import Variable
19+
from xarray.namedarray.parallelcompat import get_chunked_array_type
20+
from xarray.namedarray.pycompat import is_chunked_array
2021

2122

2223
def create_vlen_dtype(element_type):

xarray/coding/times.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
from xarray.core.common import contains_cftime_datetimes, is_np_datetime_like
2525
from xarray.core.duck_array_ops import asarray
2626
from xarray.core.formatting import first_n_items, format_timestamp, last_item
27-
from xarray.core.parallelcompat import T_ChunkedArray, get_chunked_array_type
2827
from xarray.core.pdcompat import nanosecond_precision_timestamp
29-
from xarray.core.pycompat import is_chunked_array, is_duck_dask_array
3028
from xarray.core.utils import emit_user_level_warning
3129
from xarray.core.variable import Variable
30+
from xarray.namedarray.parallelcompat import T_ChunkedArray, get_chunked_array_type
31+
from xarray.namedarray.pycompat import is_chunked_array
32+
from xarray.namedarray.utils import is_duck_dask_array
3233

3334
try:
3435
import cftime

xarray/coding/variables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import pandas as pd
1212

1313
from xarray.core import dtypes, duck_array_ops, indexing
14-
from xarray.core.parallelcompat import get_chunked_array_type
15-
from xarray.core.pycompat import is_chunked_array
1614
from xarray.core.variable import Variable
15+
from xarray.namedarray.parallelcompat import get_chunked_array_type
16+
from xarray.namedarray.pycompat import is_chunked_array
1717

1818
if TYPE_CHECKING:
1919
T_VarTuple = tuple[tuple[Hashable, ...], Any, dict, dict]
@@ -163,7 +163,7 @@ def lazy_elemwise_func(array, func: Callable, dtype: np.typing.DTypeLike):
163163
if is_chunked_array(array):
164164
chunkmanager = get_chunked_array_type(array)
165165

166-
return chunkmanager.map_blocks(func, array, dtype=dtype)
166+
return chunkmanager.map_blocks(func, array, dtype=dtype) # type: ignore[arg-type]
167167
else:
168168
return _ElementwiseFunctionArray(array, func, dtype)
169169

0 commit comments

Comments
 (0)