diff --git a/narwhals/_arrow/series.py b/narwhals/_arrow/series.py index be1377b4d0..70009df43c 100644 --- a/narwhals/_arrow/series.py +++ b/narwhals/_arrow/series.py @@ -12,6 +12,7 @@ from narwhals._arrow.utils import floordiv_compat from narwhals._arrow.utils import narwhals_to_native_dtype from narwhals._arrow.utils import native_to_narwhals_dtype +from narwhals._arrow.utils import parse_datetime_format from narwhals._arrow.utils import validate_column_comparand from narwhals.utils import Implementation from narwhals.utils import generate_temporary_column_name @@ -1115,8 +1116,7 @@ def to_datetime(self: Self, format: str | None) -> ArrowSeries: # noqa: A002 import pyarrow.compute as pc # ignore-banned-import() if format is None: - msg = "`format` is required for pyarrow backend." - raise ValueError(msg) + format = parse_datetime_format(self._arrow_series._native_series) return self._arrow_series._from_native_series( pc.strptime(self._arrow_series._native_series, format=format, unit="us") diff --git a/narwhals/_arrow/utils.py b/narwhals/_arrow/utils.py index 7f6fa6558d..bc8d170101 100644 --- a/narwhals/_arrow/utils.py +++ b/narwhals/_arrow/utils.py @@ -335,3 +335,88 @@ def convert_str_slice_to_int_slice( stop = columns.index(str_slice.stop) + 1 if str_slice.stop is not None else None step = str_slice.step return (start, stop, step) + + +# Regex for date, time, separator and timezone components +DATE_RE = r"(?P\d{1,4}[-/.]\d{1,2}[-/.]\d{1,4})" +SEP_RE = r"(?P\s|T)" +TIME_RE = r"(?P