Skip to content

Commit ad35a10

Browse files
pre-commit-ci[bot]max-sixtydcherian
authored
[pre-commit.ci] pre-commit autoupdate (#9202)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.7 → v0.5.0](astral-sh/ruff-pre-commit@v0.4.7...v0.5.0) - [github.com/pre-commit/mirrors-mypy: v1.10.0 → v1.10.1](pre-commit/mirrors-mypy@v1.10.0...v1.10.1) * Fix pre-commit --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <[email protected]> Co-authored-by: Deepak Cherian <[email protected]>
1 parent 45d25b9 commit ad35a10

12 files changed

+19
-19
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
- id: mixed-line-ending
1414
- repo: https://github.com/astral-sh/ruff-pre-commit
1515
# Ruff version.
16-
rev: 'v0.4.7'
16+
rev: 'v0.5.0'
1717
hooks:
1818
- id: ruff
1919
args: ["--fix", "--show-fixes"]
@@ -30,7 +30,7 @@ repos:
3030
additional_dependencies: ["black==24.4.2"]
3131
- id: blackdoc-autoupdate-black
3232
- repo: https://github.com/pre-commit/mirrors-mypy
33-
rev: v1.10.0
33+
rev: v1.10.1
3434
hooks:
3535
- id: mypy
3636
# Copied from setup.cfg

xarray/backends/zarr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No
806806
for k2, v2 in attrs.items():
807807
encoded_attrs[k2] = self.encode_attribute(v2)
808808

809-
if coding.strings.check_vlen_dtype(dtype) == str:
809+
if coding.strings.check_vlen_dtype(dtype) is str:
810810
dtype = str
811811

812812
if self._write_empty is not None:

xarray/coding/cftimeindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def __contains__(self, key: Any) -> bool:
507507
result = self.get_loc(key)
508508
return (
509509
is_scalar(result)
510-
or type(result) == slice
510+
or isinstance(result, slice)
511511
or (isinstance(result, np.ndarray) and result.size > 0)
512512
)
513513
except (KeyError, TypeError, ValueError):

xarray/coding/strings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def check_vlen_dtype(dtype):
3939

4040

4141
def is_unicode_dtype(dtype):
42-
return dtype.kind == "U" or check_vlen_dtype(dtype) == str
42+
return dtype.kind == "U" or check_vlen_dtype(dtype) is str
4343

4444

4545
def is_bytes_dtype(dtype):
46-
return dtype.kind == "S" or check_vlen_dtype(dtype) == bytes
46+
return dtype.kind == "S" or check_vlen_dtype(dtype) is bytes
4747

4848

4949
class EncodedStringCoder(VariableCoder):
@@ -104,7 +104,7 @@ def encode_string_array(string_array, encoding="utf-8"):
104104

105105
def ensure_fixed_length_bytes(var: Variable) -> Variable:
106106
"""Ensure that a variable with vlen bytes is converted to fixed width."""
107-
if check_vlen_dtype(var.dtype) == bytes:
107+
if check_vlen_dtype(var.dtype) is bytes:
108108
dims, data, attrs, encoding = unpack_for_encoding(var)
109109
# TODO: figure out how to handle this with dask
110110
data = np.asarray(data, dtype=np.bytes_)

xarray/coding/variables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def encode(self):
677677
raise NotImplementedError
678678

679679
def decode(self, variable: Variable, name: T_Name = None) -> Variable:
680-
if variable.dtype == object and variable.encoding.get("dtype", False) == str:
680+
if variable.dtype.kind == "O" and variable.encoding.get("dtype", False) is str:
681681
variable = variable.astype(variable.encoding["dtype"])
682682
return variable
683683
else:

xarray/conventions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def decode_cf_variable(
273273
var = strings.CharacterArrayCoder().decode(var, name=name)
274274
var = strings.EncodedStringCoder().decode(var)
275275

276-
if original_dtype == object:
276+
if original_dtype.kind == "O":
277277
var = variables.ObjectVLenStringCoder().decode(var)
278278
original_dtype = var.dtype
279279

xarray/tests/test_backends.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,14 @@ def test_roundtrip_empty_vlen_string_array(self) -> None:
863863
# checks preserving vlen dtype for empty arrays GH7862
864864
dtype = create_vlen_dtype(str)
865865
original = Dataset({"a": np.array([], dtype=dtype)})
866-
assert check_vlen_dtype(original["a"].dtype) == str
866+
assert check_vlen_dtype(original["a"].dtype) is str
867867
with self.roundtrip(original) as actual:
868868
assert_identical(original, actual)
869869
if np.issubdtype(actual["a"].dtype, object):
870870
# only check metadata for capable backends
871871
# eg. NETCDF3 based backends do not roundtrip metadata
872872
if actual["a"].dtype.metadata is not None:
873-
assert check_vlen_dtype(actual["a"].dtype) == str
873+
assert check_vlen_dtype(actual["a"].dtype) is str
874874
else:
875875
assert actual["a"].dtype == np.dtype("<U1")
876876

xarray/tests/test_coding_strings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
def test_vlen_dtype() -> None:
2323
dtype = strings.create_vlen_dtype(str)
24-
assert dtype.metadata["element_type"] == str
24+
assert dtype.metadata["element_type"] is str
2525
assert strings.is_unicode_dtype(dtype)
2626
assert not strings.is_bytes_dtype(dtype)
2727
assert strings.check_vlen_dtype(dtype) is str
2828

2929
dtype = strings.create_vlen_dtype(bytes)
30-
assert dtype.metadata["element_type"] == bytes
30+
assert dtype.metadata["element_type"] is bytes
3131
assert not strings.is_unicode_dtype(dtype)
3232
assert strings.is_bytes_dtype(dtype)
3333
assert strings.check_vlen_dtype(dtype) is bytes

xarray/tests/test_conventions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,10 @@ def test_encode_cf_variable_with_vlen_dtype() -> None:
564564
)
565565
encoded_v = conventions.encode_cf_variable(v)
566566
assert encoded_v.data.dtype.kind == "O"
567-
assert coding.strings.check_vlen_dtype(encoded_v.data.dtype) == str
567+
assert coding.strings.check_vlen_dtype(encoded_v.data.dtype) is str
568568

569569
# empty array
570570
v = Variable(["x"], np.array([], dtype=coding.strings.create_vlen_dtype(str)))
571571
encoded_v = conventions.encode_cf_variable(v)
572572
assert encoded_v.data.dtype.kind == "O"
573-
assert coding.strings.check_vlen_dtype(encoded_v.data.dtype) == str
573+
assert coding.strings.check_vlen_dtype(encoded_v.data.dtype) is str

xarray/tests/test_datatree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def test_methods(self):
593593
ds = create_test_data()
594594
dt: DataTree = DataTree(data=ds)
595595
assert ds.mean().identical(dt.ds.mean())
596-
assert type(dt.ds.mean()) == xr.Dataset
596+
assert isinstance(dt.ds.mean(), xr.Dataset)
597597

598598
def test_arithmetic(self, create_test_datatree):
599599
dt = create_test_datatree()

xarray/tests/test_duck_array_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def construct_dataarray(dim_num, dtype, contains_nan, dask):
347347
array = rng.randint(0, 10, size=shapes).astype(dtype)
348348
elif np.issubdtype(dtype, np.bool_):
349349
array = rng.randint(0, 1, size=shapes).astype(dtype)
350-
elif dtype == str:
350+
elif dtype is str:
351351
array = rng.choice(["a", "b", "c", "d"], size=shapes)
352352
else:
353353
raise ValueError

xarray/tests/test_variable.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ def _assertIndexedLikeNDArray(self, variable, expected_value0, expected_dtype=No
178178
# check type or dtype is consistent for both ndarray and Variable
179179
if expected_dtype is None:
180180
# check output type instead of array dtype
181-
assert type(variable.values[0]) == type(expected_value0)
182-
assert type(variable[0].values) == type(expected_value0)
181+
assert type(variable.values[0]) is type(expected_value0)
182+
assert type(variable[0].values) is type(expected_value0)
183183
elif expected_dtype is not False:
184184
assert variable.values[0].dtype == expected_dtype
185185
assert variable[0].values.dtype == expected_dtype

0 commit comments

Comments
 (0)