Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone management incompatible with pandas #10120

Closed
1 task done
PetitLepton opened this issue Aug 13, 2024 · 2 comments
Closed
1 task done

Timezone management incompatible with pandas #10120

PetitLepton opened this issue Aug 13, 2024 · 2 comments
Assignees
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation

Comments

@PetitLepton
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Hi, while a previous issue related to timezone management in pydantic and pandas was solved, see here, it seems that an incompatibility remains as shown by the code below.

The function tz_compare is indirectly used in pandera for schema validation and, therefore, validation breaks down when used with objects parsed by pydantic.

Please let me know if this issue should be reported to pandas instead. 😃

Thanks in advance for your guidance!

Example Code

from zoneinfo import ZoneInfo

from pandas._libs.tslibs import tz_compare
from pydantic_core._pydantic_core import TzInfo

assert TzInfo(0) == ZoneInfo("UTC")
assert(tz_compare(TzInfo(0), ZoneInfo("UTC")))

Python, Pydantic & OS Version

pydantic version: 2.8.2
        pydantic-core version: 2.20.1
          pydantic-core build: profile=release pgo=true
               python version: 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:40:35) [GCC 12.3.0]


pandas version: 2.1.4
@PetitLepton PetitLepton added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Aug 13, 2024
@PetitLepton
Copy link
Author

Another example related to pandas.date_range as in the previous issue which leads to an error.

from datetime import datetime
from zoneinfo import ZoneInfo

import pandas
from pydantic_core._pydantic_core import TzInfo

timestamp = datetime(1970, 1, 1, tzinfo=TzInfo(0))
pandas.date_range(start=timestamp, freq="1h", periods=1, tz=ZoneInfo("UTC"))

@Viicos Viicos self-assigned this Aug 15, 2024
@Viicos
Copy link
Member

Viicos commented Aug 15, 2024

Nothing Pydantic can really do here: pandas is special casing each subclass of the datetime.tzinfo ABC subclass (see source code of get_timezone, used by tz_compare).

@Viicos Viicos closed this as completed Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation
Projects
None yet
Development

No branches or pull requests

2 participants