From 5821a134354bad482f14a154e513b7539be0dcd9 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:11:17 +0200 Subject: [PATCH] Support ruff 0.5.0 in CI (#7009) * Revert "Fix CI by temporarily pinning ruff < 0.5.0" This reverts commit dd631431cb73c3ca434dfd6b115a6c30c5a665a5. * Use is for type comparison * Use isinstance for instance check * Replace is with equality comparison --- setup.py | 2 +- src/datasets/features/features.py | 2 +- tests/features/test_array_xd.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index dc29dd048c3..a7856b62b52 100644 --- a/setup.py +++ b/setup.py @@ -216,7 +216,7 @@ TESTS_REQUIRE.extend(VISION_REQUIRE) TESTS_REQUIRE.extend(AUDIO_REQUIRE) -QUALITY_REQUIRE = ["ruff>=0.3.0,<0.5.0"] +QUALITY_REQUIRE = ["ruff>=0.3.0"] DOCS_REQUIRE = [ # Might need to add doc-builder and some specific deps in the future diff --git a/src/datasets/features/features.py b/src/datasets/features/features.py index 0973a1fed28..df8eeffd306 100644 --- a/src/datasets/features/features.py +++ b/src/datasets/features/features.py @@ -841,7 +841,7 @@ def __array__(self, dtype=None): https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.api.extensions.ExtensionArray.html#pandas.api.extensions.ExtensionArray """ - if dtype == object: + if dtype == np.dtype(object): out = np.empty(len(self._data), dtype=object) for i in range(len(self._data)): out[i] = self._data[i] diff --git a/tests/features/test_array_xd.py b/tests/features/test_array_xd.py index 61a0fd7650e..8a50823b996 100644 --- a/tests/features/test_array_xd.py +++ b/tests/features/test_array_xd.py @@ -362,7 +362,7 @@ def test_table_to_pandas(dtype, dummy_value): features = datasets.Features({"foo": datasets.Array2D(dtype=dtype, shape=(2, 2))}) dataset = datasets.Dataset.from_dict({"foo": [[[dummy_value] * 2] * 2]}, features=features) df = dataset._data.to_pandas() - assert type(df.foo.dtype) == PandasArrayExtensionDtype + assert isinstance(df.foo.dtype, PandasArrayExtensionDtype) arr = df.foo.to_numpy() np.testing.assert_equal(arr, np.array([[[dummy_value] * 2] * 2], dtype=np.dtype(dtype)))