diff --git a/narwhals/_arrow/series_dt.py b/narwhals/_arrow/series_dt.py index 23dcab43a9..885e64a86f 100644 --- a/narwhals/_arrow/series_dt.py +++ b/narwhals/_arrow/series_dt.py @@ -30,7 +30,7 @@ def unit(self) -> TimeUnit: # NOTE: Unsafe (native). def time_zone(self) -> str | None: # NOTE: Unsafe (narwhals). return cast("Datetime", self.compliant.dtype).time_zone - def to_string(self: Self, format: str) -> ArrowSeries: # noqa: A002 + def to_string(self: Self, format: str) -> ArrowSeries: # PyArrow differs from other libraries in that %S also prints out # the fractional part of the second...:'( # https://arrow.apache.org/docs/python/generated/pyarrow.compute.strftime.html diff --git a/narwhals/_arrow/series_str.py b/narwhals/_arrow/series_str.py index 0026d89ae4..c3591376a8 100644 --- a/narwhals/_arrow/series_str.py +++ b/narwhals/_arrow/series_str.py @@ -61,7 +61,7 @@ def split(self: Self, by: str) -> ArrowSeries: split_series = pc.split_pattern(self.native, by) # type: ignore[call-overload] return self.from_native(split_series) - def to_datetime(self: Self, format: str | None) -> ArrowSeries: # noqa: A002 + def to_datetime(self: Self, format: str | None) -> ArrowSeries: format = parse_datetime_format(self.native) if format is None else format strptime: Incomplete = pc.strptime timestamp_array: pa.Array[pa.TimestampScalar[Any, Any]] = strptime( diff --git a/narwhals/_compliant/any_namespace.py b/narwhals/_compliant/any_namespace.py index d67b0a434c..a295547b6f 100644 --- a/narwhals/_compliant/any_namespace.py +++ b/narwhals/_compliant/any_namespace.py @@ -28,7 +28,7 @@ def get_categories(self) -> CompliantT_co: ... class DateTimeNamespace(_StoresCompliant[CompliantT_co], Protocol[CompliantT_co]): - def to_string(self, format: str) -> CompliantT_co: ... # noqa: A002 + def to_string(self, format: str) -> CompliantT_co: ... def replace_time_zone(self, time_zone: str | None) -> CompliantT_co: ... def convert_time_zone(self, time_zone: str) -> CompliantT_co: ... def timestamp(self, time_unit: TimeUnit) -> CompliantT_co: ... @@ -78,7 +78,7 @@ def ends_with(self, suffix: str) -> CompliantT_co: ... def contains(self, pattern: str, *, literal: bool) -> CompliantT_co: ... def slice(self, offset: int, length: int | None) -> CompliantT_co: ... def split(self, by: str) -> CompliantT_co: ... - def to_datetime(self, format: str | None) -> CompliantT_co: ... # noqa: A002 + def to_datetime(self, format: str | None) -> CompliantT_co: ... def to_lowercase(self) -> CompliantT_co: ... def to_uppercase(self) -> CompliantT_co: ... diff --git a/narwhals/_compliant/expr.py b/narwhals/_compliant/expr.py index 30e9bfa0a7..0079f6faeb 100644 --- a/narwhals/_compliant/expr.py +++ b/narwhals/_compliant/expr.py @@ -827,7 +827,7 @@ def get_categories(self) -> EagerExprT: class EagerExprDateTimeNamespace( EagerExprNamespace[EagerExprT], DateTimeNamespace[EagerExprT], Generic[EagerExprT] ): - def to_string(self, format: str) -> EagerExprT: # noqa: A002 + def to_string(self, format: str) -> EagerExprT: return self.compliant._reuse_series_namespace("dt", "to_string", format=format) def replace_time_zone(self, time_zone: str | None) -> EagerExprT: @@ -990,7 +990,7 @@ def slice(self, offset: int, length: int | None) -> EagerExprT: def split(self, by: str) -> EagerExprT: return self.compliant._reuse_series_namespace("str", "split", by=by) - def to_datetime(self, format: str | None) -> EagerExprT: # noqa: A002 + def to_datetime(self, format: str | None) -> EagerExprT: return self.compliant._reuse_series_namespace("str", "to_datetime", format=format) def to_lowercase(self) -> EagerExprT: diff --git a/narwhals/_dask/expr_dt.py b/narwhals/_dask/expr_dt.py index b7355dad4b..8ef968a875 100644 --- a/narwhals/_dask/expr_dt.py +++ b/narwhals/_dask/expr_dt.py @@ -72,9 +72,9 @@ def weekday(self: Self) -> DaskExpr: "weekday", ) - def to_string(self: Self, format: str) -> DaskExpr: # noqa: A002 + def to_string(self: Self, format: str) -> DaskExpr: return self._compliant_expr._from_call( - lambda _input, format: _input.dt.strftime(format.replace("%.f", ".%f")), # noqa: A006 + lambda _input, format: _input.dt.strftime(format.replace("%.f", ".%f")), "strftime", format=format, ) diff --git a/narwhals/_dask/expr_str.py b/narwhals/_dask/expr_str.py index d30cca157e..9de32fae0c 100644 --- a/narwhals/_dask/expr_str.py +++ b/narwhals/_dask/expr_str.py @@ -88,9 +88,9 @@ def split(self: Self, by: str) -> DaskExpr: by=by, ) - def to_datetime(self: Self, format: str | None) -> DaskExpr: # noqa: A002 + def to_datetime(self: Self, format: str | None) -> DaskExpr: return self._compliant_expr._from_call( - lambda _input, format: dd.to_datetime(_input, format=format), # noqa: A006 + lambda _input, format: dd.to_datetime(_input, format=format), "to_datetime", format=format, ) diff --git a/narwhals/_duckdb/expr_dt.py b/narwhals/_duckdb/expr_dt.py index 924e1cee0d..e5e75a8004 100644 --- a/narwhals/_duckdb/expr_dt.py +++ b/narwhals/_duckdb/expr_dt.py @@ -67,7 +67,7 @@ def nanosecond(self: Self) -> DuckDBExpr: "nanosecond", ) - def to_string(self: Self, format: str) -> DuckDBExpr: # noqa: A002 + def to_string(self: Self, format: str) -> DuckDBExpr: return self._compliant_expr._from_call( lambda _input: FunctionExpression("strftime", _input, lit(format)), "to_string", diff --git a/narwhals/_duckdb/expr_str.py b/narwhals/_duckdb/expr_str.py index 6f29898494..191ea40291 100644 --- a/narwhals/_duckdb/expr_str.py +++ b/narwhals/_duckdb/expr_str.py @@ -106,7 +106,7 @@ def replace(self: Self, pattern: str, value: str, *, literal: bool, n: int) -> N msg = "`replace` is currently not supported for DuckDB" raise NotImplementedError(msg) - def to_datetime(self: Self, format: str | None) -> DuckDBExpr: # noqa: A002 + def to_datetime(self: Self, format: str | None) -> DuckDBExpr: if format is None: msg = "Cannot infer format with DuckDB backend, please specify `format` explicitly." raise NotImplementedError(msg) diff --git a/narwhals/_pandas_like/series_dt.py b/narwhals/_pandas_like/series_dt.py index f9cad1e63c..a30a7e7908 100644 --- a/narwhals/_pandas_like/series_dt.py +++ b/narwhals/_pandas_like/series_dt.py @@ -178,7 +178,7 @@ def total_nanoseconds(self: Self) -> PandasLikeSeries: s_abs = s_abs.astype(int_dtype_mapper(s.dtype)) return self._compliant_series._from_native_series(s_abs * s_sign) - def to_string(self: Self, format: str) -> PandasLikeSeries: # noqa: A002 + def to_string(self: Self, format: str) -> PandasLikeSeries: # Polars' parser treats `'%.f'` as pandas does `'.%f'` # PyArrow interprets `'%S'` as "seconds, plus fractional seconds" # and doesn't support `%f` diff --git a/narwhals/_pandas_like/series_str.py b/narwhals/_pandas_like/series_str.py index 6e75908489..68a8134ffe 100644 --- a/narwhals/_pandas_like/series_str.py +++ b/narwhals/_pandas_like/series_str.py @@ -84,7 +84,7 @@ def split(self: Self, by: str) -> PandasLikeSeries: self._compliant_series._native_series.str.split(pat=by), ) - def to_datetime(self: Self, format: str | None) -> PandasLikeSeries: # noqa: A002 + def to_datetime(self: Self, format: str | None) -> PandasLikeSeries: if format is not None and any(x in format for x in ("%z", "Z")): # We know that the inputs are timezone-aware, so we can directly pass # `utc=True` for better performance. diff --git a/narwhals/_spark_like/expr_str.py b/narwhals/_spark_like/expr_str.py index 19a368ad54..36bf2990f1 100644 --- a/narwhals/_spark_like/expr_str.py +++ b/narwhals/_spark_like/expr_str.py @@ -106,7 +106,7 @@ def to_lowercase(self: Self) -> SparkLikeExpr: self._compliant_expr._F.lower, "to_lowercase" ) - def to_datetime(self: Self, format: str | None) -> SparkLikeExpr: # noqa: A002 + def to_datetime(self: Self, format: str | None) -> SparkLikeExpr: F = self._compliant_expr._F # noqa: N806 if not format: function = F.to_timestamp @@ -123,11 +123,11 @@ def to_datetime(self: Self, format: str | None) -> SparkLikeExpr: # noqa: A002 ) -def is_naive_format(format: str) -> bool: # noqa: A002 +def is_naive_format(format: str) -> bool: return not any(x in format for x in ("%s", "%z", "Z")) -def strptime_to_pyspark_format(format: str) -> str: # noqa: A002 +def strptime_to_pyspark_format(format: str) -> str: """Converts a Python strptime datetime format string to a PySpark datetime format string.""" # Mapping from Python strptime format to PySpark format diff --git a/narwhals/expr_dt.py b/narwhals/expr_dt.py index b65406f18d..293c0e5c41 100644 --- a/narwhals/expr_dt.py +++ b/narwhals/expr_dt.py @@ -575,7 +575,7 @@ def total_nanoseconds(self: Self) -> ExprT: self._expr._metadata, ) - def to_string(self: Self, format: str) -> ExprT: # noqa: A002 + def to_string(self: Self, format: str) -> ExprT: """Convert a Date/Time/Datetime column into a String column with the given format. Arguments: diff --git a/narwhals/expr_str.py b/narwhals/expr_str.py index 3b837779ba..34ad9ad4c4 100644 --- a/narwhals/expr_str.py +++ b/narwhals/expr_str.py @@ -367,7 +367,7 @@ def tail(self: Self, n: int = 5) -> ExprT: self._expr._metadata, ) - def to_datetime(self: Self, format: str | None = None) -> ExprT: # noqa: A002 + def to_datetime(self: Self, format: str | None = None) -> ExprT: """Convert to Datetime dtype. Notes: diff --git a/narwhals/series_dt.py b/narwhals/series_dt.py index 6a99aed410..2c34d21371 100644 --- a/narwhals/series_dt.py +++ b/narwhals/series_dt.py @@ -487,7 +487,7 @@ def total_nanoseconds(self: Self) -> SeriesT: self._narwhals_series._compliant_series.dt.total_nanoseconds() ) - def to_string(self: Self, format: str) -> SeriesT: # noqa: A002 + def to_string(self: Self, format: str) -> SeriesT: """Convert a Date/Time/Datetime series into a String series with the given format. Arguments: diff --git a/narwhals/series_str.py b/narwhals/series_str.py index 2a74ea3642..8c861280a7 100644 --- a/narwhals/series_str.py +++ b/narwhals/series_str.py @@ -369,7 +369,7 @@ def to_lowercase(self: Self) -> SeriesT: self._narwhals_series._compliant_series.str.to_lowercase() ) - def to_datetime(self: Self, format: str | None = None) -> SeriesT: # noqa: A002 + def to_datetime(self: Self, format: str | None = None) -> SeriesT: """Parse Series with strings to a Series with Datetime dtype. Notes: diff --git a/pyproject.toml b/pyproject.toml index 72f17ec10e..2013c149eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -158,6 +158,9 @@ ignore = [ "TD004", # missing-todo-colon ] +[tool.ruff.lint.flake8-builtins] +builtins-ignorelist = ["format"] + [tool.ruff.lint.per-file-ignores] "narwhals/expr_dt.py" = ["RUF002"] "tests/*" = ["S101"] diff --git a/tests/expr_and_series/str/to_datetime_test.py b/tests/expr_and_series/str/to_datetime_test.py index 0c11a39b96..fda87a0b97 100644 --- a/tests/expr_and_series/str/to_datetime_test.py +++ b/tests/expr_and_series/str/to_datetime_test.py @@ -206,7 +206,7 @@ def test_pyarrow_infer_datetime_raise_inconsistent_date_fmt( def test_to_datetime_tz_aware( constructor: Constructor, request: pytest.FixtureRequest, - format: str | None, # noqa: A002 + format: str | None, ) -> None: if "pyarrow_table" in str(constructor) and PYARROW_VERSION < (13,): # bugged