Skip to content

Commit

Permalink
chore: ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Jul 15, 2024
1 parent a5276cd commit 08d65aa
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 43 deletions.
3 changes: 2 additions & 1 deletion narwhals/_arrow/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions narwhals/_interchange/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
raise AssertionError(msg)
if interchange_dtype[0] == DtypeKind.UINT:
if interchange_dtype[1] == 64:
return dtypes.UInt64()
Expand All @@ -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"
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"
raise AssertionError(msg)
if interchange_dtype[0] == DtypeKind.BOOL:
return dtypes.Boolean()
if interchange_dtype[0] == DtypeKind.STRING:
Expand Down
5 changes: 2 additions & 3 deletions narwhals/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
5 changes: 2 additions & 3 deletions narwhals/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ def concat(
how: Literal["horizontal", "vertical"] = "vertical",
) -> FrameT:
if how not in ("horizontal", "vertical"):
raise NotImplementedError(
"Only horizontal and vertical concatenations are supported"
)
msg = "Only horizontal and vertical concatenations are supported"
raise NotImplementedError(msg)
if not items:
msg = "No items to concatenate"
raise ValueError(msg)
Expand Down
8 changes: 4 additions & 4 deletions narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
53 changes: 28 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,37 @@ 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"]
"tests/*" = [
"S101",
]
"utils/*" = [
"S311",
"PTH123",
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
force-single-line = true
Expand Down
7 changes: 3 additions & 4 deletions tests/frame/write_parquet_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import os
from typing import Any

import pandas as pd
Expand All @@ -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()

0 comments on commit 08d65aa

Please sign in to comment.