Skip to content

Parsing ambiguous timestamps in polars.from_repr #26797

@denisrossetre

Description

@denisrossetre

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

pl.from_repr("""\
shape: (2, 3)
┌─────────────────────────────┬─────────────┬────────────┐
│ timestamp                   ┆ consumption ┆ production │
│ ---                         ┆ ---         ┆ ---        │
│ datetime[μs, Europe/Zurich] ┆ f64         ┆ f64        │
╞═════════════════════════════╪═════════════╪════════════╡
│ 2025-10-26 01:45:00 CEST    ┆ 0.010044    ┆ 0.0        │
│ 2025-10-26 02:00:00 CEST    ┆ 0.010044    ┆ 0.0        │
└─────────────────────────────┴─────────────┴────────────┘\
""")

Log output

async thread count: 4
Traceback (most recent call last):
  File "C:\Users\rossetd\projects\middleware\testpolars.py", line 2, in <module>
    pl.from_repr("""\
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\_utils\deprecation.py", line 128, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\convert\general.py", line 798, in from_repr
    return _from_dataframe_repr(m)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\convert\general.py", line 949, in _from_dataframe_repr
    return _cast_repr_strings_with_schema(df, schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\_utils\various.py", line 419, in _cast_repr_strings_with_schema
    return df.with_columns(**cast_cols) if cast_cols else df
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\dataframe\frame.py", line 10473, in with_columns
    .collect(optimizations=QueryOptFlags._eager())
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\_utils\deprecation.py", line 97, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\lazyframe\opt_flags.py", line 326, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rossetd\projects\middleware\.venv\Lib\site-packages\polars\lazyframe\frame.py", line 2440, in collect
    return wrap_df(ldf.collect(engine, callback))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ComputeError: datetime '2025-10-26 02:00:00' is ambiguous in time zone 'Europe/Zurich'. Please use `ambiguous` to tell how it should be localized.

Issue description

The parsing fails as if the datetime were ambiguous but this is not the case.

Expected behavior

Parse the dataframe correctly including the 2am timestamp.

Installed versions

Details
--------Version info---------
Polars:              1.38.1
Index type:          UInt32
Platform:            Linux-6.10.14-linuxkit-x86_64-with-glibc2.36
Python:              3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0]
Runtime:             rt32

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                1.40.15
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           3.10.5
numpy                2.3.2
openpyxl             <not installed>
pandas               2.3.3
polars_cloud         <not installed>
pyarrow              21.0.0
pydantic             2.11.7
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>```

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageAwaiting prioritization by a maintainerpythonRelated to Python Polars

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions