Skip to content

Commit 2d3f984

Browse files
authored
Merge branch 'main' into groupby-save-codes-new
2 parents ea3ed87 + e04109f commit 2d3f984

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
files: ^xarray/
1717
- repo: https://github.com/charliermarsh/ruff-pre-commit
1818
# Ruff version.
19-
rev: 'v0.0.248'
19+
rev: 'v0.0.253'
2020
hooks:
2121
- id: ruff
2222
args: ["--fix"]

xarray/backends/zarr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _get_zarr_dims_and_attrs(zarr_obj, dimension_key, try_nczarr):
207207
"which are required for xarray to determine variable dimensions."
208208
) from e
209209

210-
nc_attrs = [attr for attr in zarr_obj.attrs if attr.startswith("_NC")]
210+
nc_attrs = [attr for attr in zarr_obj.attrs if attr.lower().startswith("_nc")]
211211
attributes = HiddenKeyDict(zarr_obj.attrs, [dimension_key] + nc_attrs)
212212
return dimensions, attributes
213213

@@ -495,7 +495,7 @@ def get_attrs(self):
495495
return {
496496
k: v
497497
for k, v in self.zarr_group.attrs.asdict().items()
498-
if not k.startswith("_NC")
498+
if not k.lower().startswith("_nc")
499499
}
500500

501501
def get_dimensions(self):

xarray/core/types.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Any,
88
Callable,
99
Literal,
10-
Protocol,
1110
SupportsIndex,
1211
TypeVar,
1312
Union,
@@ -18,6 +17,7 @@
1817
from packaging.version import Version
1918

2019
if TYPE_CHECKING:
20+
from numpy._typing import _SupportsDType
2121
from numpy.typing import ArrayLike
2222

2323
from xarray.backends.common import BackendEntrypoint
@@ -50,19 +50,12 @@
5050
_ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]]
5151
_DTypeLikeNested = Any # TODO: wait for support for recursive types
5252

53-
# once NumPy 1.21 is minimum version, use NumPys definition directly
54-
# 1.20 uses a non-generic Protocol (like we define here for simplicity)
55-
class _SupportsDType(Protocol):
56-
@property
57-
def dtype(self) -> np.dtype:
58-
...
59-
6053
# Xarray requires a Mapping[Hashable, dtype] in many places which
6154
# conflics with numpys own DTypeLike (with dtypes for fields).
6255
# https://numpy.org/devdocs/reference/typing.html#numpy.typing.DTypeLike
6356
# This is a copy of this DTypeLike that allows only non-Mapping dtypes.
6457
DTypeLikeSave = Union[
65-
np.dtype,
58+
np.dtype[Any],
6659
# default data type (float64)
6760
None,
6861
# array-scalar types and generic types
@@ -78,7 +71,7 @@ def dtype(self) -> np.dtype:
7871
# because numpy does the same?
7972
list[Any],
8073
# anything with a dtype attribute
81-
_SupportsDType,
74+
_SupportsDType[np.dtype[Any]],
8275
]
8376
try:
8477
from cftime import datetime as CFTimeDatetime

xarray/tests/test_backends.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -5663,12 +5663,14 @@ def test_write_file_from_np_str(str_type, tmpdir) -> None:
56635663
@requires_zarr
56645664
@requires_netCDF4
56655665
class TestNCZarr:
5666-
@staticmethod
5667-
def _create_nczarr(filename):
5668-
netcdfc_version = Version(nc4.getlibversion().split()[0])
5669-
if netcdfc_version < Version("4.8.1"):
5666+
@property
5667+
def netcdfc_version(self):
5668+
return Version(nc4.getlibversion().split()[0])
5669+
5670+
def _create_nczarr(self, filename):
5671+
if self.netcdfc_version < Version("4.8.1"):
56705672
pytest.skip("requires netcdf-c>=4.8.1")
5671-
if (platform.system() == "Windows") and (netcdfc_version == Version("4.8.1")):
5673+
if platform.system() == "Windows" and self.netcdfc_version == Version("4.8.1"):
56725674
# Bug in netcdf-c==4.8.1 (typo: Nan instead of NaN)
56735675
# https://github.com/Unidata/netcdf-c/issues/2265
56745676
pytest.skip("netcdf-c==4.8.1 has issues on Windows")
@@ -5678,9 +5680,7 @@ def _create_nczarr(filename):
56785680
# https://github.com/Unidata/netcdf-c/issues/2259
56795681
ds = ds.drop_vars("dim3")
56805682

5681-
# netcdf-c>4.8.1 will add _ARRAY_DIMENSIONS by default
5682-
mode = "nczarr" if netcdfc_version == Version("4.8.1") else "nczarr,noxarray"
5683-
ds.to_netcdf(f"file://{filename}#mode={mode}")
5683+
ds.to_netcdf(f"file://{filename}#mode=nczarr")
56845684
return ds
56855685

56865686
def test_open_nczarr(self) -> None:
@@ -5700,6 +5700,9 @@ def test_overwriting_nczarr(self) -> None:
57005700
@pytest.mark.parametrize("mode", ["a", "r+"])
57015701
@pytest.mark.filterwarnings("ignore:.*non-consolidated metadata.*")
57025702
def test_raise_writing_to_nczarr(self, mode) -> None:
5703+
if self.netcdfc_version > Version("4.8.1"):
5704+
pytest.skip("netcdf-c>4.8.1 adds the _ARRAY_DIMENSIONS attribute")
5705+
57035706
with create_tmp_file(suffix=".zarr") as tmp:
57045707
ds = self._create_nczarr(tmp)
57055708
with pytest.raises(

0 commit comments

Comments
 (0)