From 5824a2142dda1b2d29046f075e2b2df53cc840d9 Mon Sep 17 00:00:00 2001 From: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com> Date: Tue, 16 Jul 2024 09:14:00 +0200 Subject: [PATCH] chore: ruff rules (#527) * chore: ruff rules * format * pragma no cover --- narwhals/_arrow/dataframe.py | 3 +- narwhals/_interchange/dataframe.py | 9 ++++-- narwhals/expression.py | 5 ++-- narwhals/functions.py | 7 ++--- narwhals/utils.py | 8 +++--- pyproject.toml | 46 ++++++++++++++---------------- tests/frame/write_parquet_test.py | 7 ++--- 7 files changed, 42 insertions(+), 43 deletions(-) diff --git a/narwhals/_arrow/dataframe.py b/narwhals/_arrow/dataframe.py index 10696d6d4..94dccd0c5 100644 --- a/narwhals/_arrow/dataframe.py +++ b/narwhals/_arrow/dataframe.py @@ -343,7 +343,8 @@ def collect(self) -> ArrowDataFrame: ) def clone(self) -> Self: - raise NotImplementedError("clone is not yet supported on PyArrow tables") + msg = "clone is not yet supported on PyArrow tables" + raise NotImplementedError(msg) def is_empty(self: Self) -> bool: return self.shape[0] == 0 diff --git a/narwhals/_interchange/dataframe.py b/narwhals/_interchange/dataframe.py index 16c8c54de..c7fc5ea3d 100644 --- a/narwhals/_interchange/dataframe.py +++ b/narwhals/_interchange/dataframe.py @@ -34,7 +34,8 @@ def map_interchange_dtype_to_narwhals_dtype( return dtypes.Int16() if interchange_dtype[1] == 8: return dtypes.Int8() - raise AssertionError("Invalid bit width for INT") + msg = "Invalid bit width for INT" # pragma: no cover + raise AssertionError(msg) if interchange_dtype[0] == DtypeKind.UINT: if interchange_dtype[1] == 64: return dtypes.UInt64() @@ -44,13 +45,15 @@ def map_interchange_dtype_to_narwhals_dtype( return dtypes.UInt16() if interchange_dtype[1] == 8: return dtypes.UInt8() - raise AssertionError("Invalid bit width for UINT") + msg = "Invalid bit width for UINT" # pragma: no cover + raise AssertionError(msg) if interchange_dtype[0] == DtypeKind.FLOAT: if interchange_dtype[1] == 64: return dtypes.Float64() if interchange_dtype[1] == 32: return dtypes.Float32() - raise AssertionError("Invalid bit width for FLOAT") + msg = "Invalid bit width for FLOAT" # pragma: no cover + raise AssertionError(msg) if interchange_dtype[0] == DtypeKind.BOOL: return dtypes.Boolean() if interchange_dtype[0] == DtypeKind.STRING: diff --git a/narwhals/expression.py b/narwhals/expression.py index 02f7644d4..a6af772a1 100644 --- a/narwhals/expression.py +++ b/narwhals/expression.py @@ -951,9 +951,8 @@ def is_in(self, other: Any) -> Self: if isinstance(other, Iterable) and not isinstance(other, (str, bytes)): return self.__class__(lambda plx: self._call(plx).is_in(other)) else: - raise NotImplementedError( - "Narwhals `is_in` doesn't accept expressions as an argument, as opposed to Polars. You should provide an iterable instead." - ) + msg = "Narwhals `is_in` doesn't accept expressions as an argument, as opposed to Polars. You should provide an iterable instead." + raise NotImplementedError(msg) def filter(self, *predicates: Any) -> Self: """ diff --git a/narwhals/functions.py b/narwhals/functions.py index 9184a8cf3..24d299be6 100644 --- a/narwhals/functions.py +++ b/narwhals/functions.py @@ -28,10 +28,9 @@ def concat( *, how: Literal["horizontal", "vertical"] = "vertical", ) -> FrameT: - if how not in ("horizontal", "vertical"): - raise NotImplementedError( - "Only horizontal and vertical concatenations are supported" - ) + if how not in ("horizontal", "vertical"): # pragma: no cover + msg = "Only horizontal and vertical concatenations are supported" + raise NotImplementedError(msg) if not items: msg = "No items to concatenate" raise ValueError(msg) diff --git a/narwhals/utils.py b/narwhals/utils.py index ee19d4b6a..1f6a9074a 100644 --- a/narwhals/utils.py +++ b/narwhals/utils.py @@ -92,7 +92,8 @@ def validate_same_library(items: Iterable[Any]) -> None: len({item._compliant_frame._implementation for item in items}) == 1 ): return - raise NotImplementedError("Cross-library comparisons aren't supported") + msg = "Cross-library comparisons aren't supported" + raise NotImplementedError(msg) def validate_laziness(items: Iterable[Any]) -> None: @@ -103,9 +104,8 @@ def validate_laziness(items: Iterable[Any]) -> None: all(isinstance(item, LazyFrame) for item in items) ): return - raise NotImplementedError( - "The items to concatenate should either all be eager, or all lazy" - ) + msg = "The items to concatenate should either all be eager, or all lazy" + raise NotImplementedError(msg) def maybe_align_index(lhs: T, rhs: Series | BaseFrame[Any]) -> T: diff --git a/pyproject.toml b/pyproject.toml index 8976a515d..434e74fb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,34 +43,32 @@ lint.select = [ "ALL", ] lint.ignore = [ - 'A001', - 'A003', - 'ANN101', - 'ANN401', - 'C901', - 'COM812', - 'D', - 'DTZ001', - 'E501', - 'EM101', - 'FIX', - 'ISC001', - 'PD901', # This is a auxiliary library so dataframe variables have no concrete business meaning - 'PLR0911', - 'PLR0912', - 'PLR0913', - 'PLR2004', - 'PTH', - 'RET505', - 'SLF001', - 'TD003', - 'TRY003', # TODO(Unassigned): enable - 'TRY004' + "A001", + "ANN101", + "ANN401", + "C901", + "COM812", + "D", + "DTZ001", + "E501", + "FIX", + "ISC001", + "PD901", # This is a auxiliary library so dataframe variables have no concrete business meaning + "PLR0911", + "PLR0912", + "PLR0913", + "PLR2004", + "RET505", + "SLF001", + "TD003", ] [tool.ruff.lint.per-file-ignores] "tests/*" = ["S101"] -"utils/*" = ["S311"] +"utils/*" = ["S311", "PTH123"] + +[tool.ruff.lint.pydocstyle] +convention = "google" [tool.ruff.lint.isort] force-single-line = true diff --git a/tests/frame/write_parquet_test.py b/tests/frame/write_parquet_test.py index 88e35b3fa..f0735692f 100644 --- a/tests/frame/write_parquet_test.py +++ b/tests/frame/write_parquet_test.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os from typing import Any import pandas as pd @@ -16,6 +15,6 @@ parse_version(pd.__version__) < parse_version("2.0.0"), reason="too old for pyarrow" ) def test_write_parquet(constructor: Any, tmpdir: pytest.TempdirFactory) -> None: - path = str(tmpdir / "foo.parquet") # type: ignore[operator] - nw.from_native(constructor(data), eager_only=True).write_parquet(path) - assert os.path.exists(path) + path = tmpdir / "foo.parquet" # type: ignore[operator] + nw.from_native(constructor(data), eager_only=True).write_parquet(str(path)) + assert path.exists()