File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 66
77from ibis .expr .datatypes import Timestamp
88
9+ from narwhals .utils import _is_naive_format
910from narwhals .utils import not_implemented
1011
1112if TYPE_CHECKING :
@@ -103,7 +104,3 @@ def to_datetime(self, format: str | None) -> IbisExpr:
103104 return self ._compliant_expr ._with_callable (fn (format ))
104105
105106 replace = not_implemented ()
106-
107-
108- def _is_naive_format (format_ : str ) -> bool :
109- return not any (x in format_ for x in ("%s" , "%z" , "Z" ))
Original file line number Diff line number Diff line change 33from functools import partial
44from typing import TYPE_CHECKING
55
6+ from narwhals .utils import _is_naive_format
7+
68if TYPE_CHECKING :
79 from sqlframe .base .column import Column
810
@@ -100,7 +102,7 @@ def to_datetime(self, format: str | None) -> SparkLikeExpr:
100102 F = self ._compliant_expr ._F # noqa: N806
101103 if not format :
102104 function = F .to_timestamp
103- elif is_naive_format (format ):
105+ elif _is_naive_format (format ):
104106 function = partial (
105107 F .to_timestamp_ntz , format = F .lit (strptime_to_pyspark_format (format ))
106108 )
@@ -112,10 +114,6 @@ def to_datetime(self, format: str | None) -> SparkLikeExpr:
112114 )
113115
114116
115- def is_naive_format (format : str ) -> bool :
116- return not any (x in format for x in ("%s" , "%z" , "Z" ))
117-
118-
119117def strptime_to_pyspark_format (format : str ) -> str :
120118 """Converts a Python strptime datetime format string to a PySpark datetime format string."""
121119 # Mapping from Python strptime format to PySpark format
Original file line number Diff line number Diff line change @@ -1745,6 +1745,24 @@ def unstable(fn: _Fn, /) -> _Fn:
17451745 return fn
17461746
17471747
1748+ def _is_naive_format (format : str ) -> bool :
1749+ """Determines if a datetime format string is 'naive', i.e., does not include timezone information.
1750+
1751+ A format is considered naive if it does not contain any of the following
1752+
1753+ - '%s': Unix timestamp
1754+ - '%z': UTC offset
1755+ - 'Z' : UTC timezone designator
1756+
1757+ Arguments:
1758+ format: The datetime format string to check.
1759+
1760+ Returns:
1761+ bool: True if the format is naive (does not include timezone info), False otherwise.
1762+ """
1763+ return not any (x in format for x in ("%s" , "%z" , "Z" ))
1764+
1765+
17481766if TYPE_CHECKING :
17491767 import sys
17501768
You can’t perform that action at this time.
0 commit comments