Skip to content

Commit 7072f70

Browse files
ocefpafpre-commit-ci[bot]dcherian
authored
add min xarray pin on run and numpy py ver linters (#536)
* add min xarray pin on run and numpy py ver linters * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update accessor.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Deepak Cherian <[email protected]>
1 parent bf9ba5a commit 7072f70

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed

cf_xarray/accessor.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
Any,
1919
Literal,
2020
TypeVar,
21-
Union,
2221
cast,
2322
overload,
2423
)
@@ -89,7 +88,7 @@
8988
ATTRS["vertical"] = ATTRS["Z"]
9089

9190
# Type for Mapper functions
92-
Mapper = Callable[[Union[DataArray, Dataset], Hashable], list[Hashable]]
91+
Mapper = Callable[[DataArray | Dataset, Hashable], list[Hashable]]
9392

9493
# Type for decorators
9594
F = TypeVar("F", bound=Callable[..., Any])
@@ -1150,9 +1149,10 @@ def create_flag_dict(da) -> Mapping[Hashable, FlagParam]:
11501149
)
11511150

11521151
flag_params = tuple(
1153-
FlagParam(mask, value) for mask, value in zip(flag_masks, flag_values)
1152+
FlagParam(mask, value)
1153+
for mask, value in zip(flag_masks, flag_values, strict=False)
11541154
)
1155-
return dict(zip(flag_meanings, flag_params))
1155+
return dict(zip(flag_meanings, flag_params, strict=False))
11561156

11571157

11581158
class CFAccessor:
@@ -1368,7 +1368,7 @@ def curvefit(
13681368
kwargs: dict[str, Any] | None = None,
13691369
):
13701370
if coords is not None:
1371-
if isinstance(coords, (Hashable, DataArray)):
1371+
if isinstance(coords, Hashable | DataArray):
13721372
coords_iter: Iterable[Hashable | DataArray] = [coords]
13731373
else:
13741374
coords_iter = coords
@@ -3024,7 +3024,7 @@ def _extract_flags(self, flags: Sequence[Hashable] | None = None) -> Dataset:
30243024
x = self._obj.astype("i")
30253025
bit_comp = x & bit_mask
30263026

3027-
for i, (flag, value) in enumerate(zip(flags_reduced, values)):
3027+
for i, (flag, value) in enumerate(zip(flags_reduced, values, strict=False)):
30283028
bit = bit_comp.isel(_mask=i)
30293029
if value is not None:
30303030
out[flag] = bit == value

cf_xarray/coding.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def encode_multi_index_as_compress(ds, idxnames=None):
4646
encoded = ds.reset_index(idxnames)
4747
for idxname in idxnames:
4848
mindex = ds.indexes[idxname]
49-
coords = dict(zip(mindex.names, mindex.levels))
49+
coords = dict(zip(mindex.names, mindex.levels, strict=False))
5050
encoded.update(coords)
5151
for c in coords:
5252
encoded[c].attrs = ds[c].attrs
@@ -112,13 +112,16 @@ def decode_compress_to_multi_index(encoded, idxnames=None):
112112

113113
variables = {
114114
dim: encoded[dim].isel({dim: xr.Variable(data=index, dims=idxname)})
115-
for dim, index in zip(names, indices)
115+
for dim, index in zip(names, indices, strict=False)
116116
}
117117
decoded = decoded.assign_coords(variables).set_xindex(
118118
names, PandasMultiIndex
119119
)
120120
except ImportError:
121-
arrays = [encoded[dim].data[index] for dim, index in zip(names, indices)]
121+
arrays = [
122+
encoded[dim].data[index]
123+
for dim, index in zip(names, indices, strict=False)
124+
]
122125
mindex = pd.MultiIndex.from_arrays(arrays, names=names)
123126
decoded.coords[idxname] = mindex
124127

cf_xarray/formatting.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ def _format_flags(accessor, rich):
268268
table.add_column("Value", justify="right")
269269
table.add_column("Bits", justify="center")
270270

271-
for val, bit, key in zip(value_text, bit_text, flag_dict):
271+
for val, bit, key in zip(value_text, bit_text, flag_dict, strict=False):
272272
table.add_row(_format_cf_name(key, rich), val, bit)
273273

274274
return table
275275

276276
else:
277277
rows = []
278-
for val, bit, key in zip(value_text, bit_text, flag_dict):
278+
for val, bit, key in zip(value_text, bit_text, flag_dict, strict=False):
279279
rows.append(
280280
f"{TAB}{_format_cf_name(key, rich):>{key_width}}: {TAB} {val} {bit}"
281281
)

cf_xarray/scripts/make_doc.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def make_criteria_csv():
3636
df.transpose().to_csv(os.path.join(csv_dir, "all_criteria.csv"))
3737

3838
# Axes and coordinates
39-
for keys, name in zip([_AXIS_NAMES, _COORD_NAMES], ["axes", "coords"]):
39+
for keys, name in zip(
40+
[_AXIS_NAMES, _COORD_NAMES], ["axes", "coords"], strict=False
41+
):
4042
subdf = df[sorted(keys)].dropna(axis=1, how="all")
4143
subdf = subdf.dropna(axis=1, how="all").transpose()
4244
subdf.transpose().to_csv(os.path.join(csv_dir, f"{name}_criteria.csv"))

cf_xarray/sgrid.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def parse_axes(ds):
2424
zip(
2525
axes_names,
2626
({k} for k in grid.attrs["node_dimensions"].split(" ")),
27+
strict=False,
2728
)
2829
)
2930
for attr in SGRID_DIM_ATTRS:
3031
if attr in grid.attrs:
3132
matches = re.findall(pattern, grid.attrs[attr] + "\n")
3233
assert len(matches) == ndim, matches
33-
for ax, match in zip(axes_names, matches):
34+
for ax, match in zip(axes_names, matches, strict=False):
3435
axes[ax].update(set(match[:2]))
3536

3637
if ndim == 2 and "vertical_dimensions" in grid.attrs:

cf_xarray/tests/test_accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ def test_groupby_special_ops() -> None:
15441544
grouped = airds.groupby_bins("lat", np.arange(20, 50, 10))
15451545

15461546
# __iter__
1547-
for (label, group), (cflabel, cfgroup) in zip(grouped, cfgrouped):
1547+
for (label, group), (cflabel, cfgroup) in zip(grouped, cfgrouped, strict=False):
15481548
assert label == cflabel
15491549
assert_identical(group, cfgroup)
15501550

cf_xarray/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def parse_cell_methods_attr(attr: str) -> dict[str, str]:
8181
if len(strings) % 2 != 0:
8282
raise ValueError(f"attrs['cell_measures'] = {attr!r} is malformed.")
8383

84-
return dict(zip(strings[slice(0, None, 2)], strings[slice(1, None, 2)]))
84+
return dict(
85+
zip(strings[slice(0, None, 2)], strings[slice(1, None, 2)], strict=False)
86+
)
8587

8688

8789
def invert_mappings(*mappings):

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ classifiers = [
1616
"Programming Language :: Python :: 3.12",
1717
]
1818
dependencies = [
19-
"xarray",
19+
"xarray>=2022.03.0",
2020
]
2121
dynamic = ["version"]
2222

@@ -54,10 +54,10 @@ write_to_template= '__version__ = "{version}"'
5454
tag_regex= "^(?P<prefix>v)?(?P<version>[^\\+]+)(?P<suffix>.*)?$"
5555

5656
[tool.black]
57-
target-version = ["py39"]
57+
target-version = ["py310"]
5858

5959
[tool.ruff]
60-
target-version = "py39"
60+
target-version = "py310"
6161
builtins = ["ellipsis"]
6262
exclude = [
6363
".eggs",

0 commit comments

Comments
 (0)