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

Pendulum datetime timezone bug #1839

Open
1 task done
vladjohnson opened this issue Oct 25, 2024 · 0 comments
Open
1 task done

Pendulum datetime timezone bug #1839

vladjohnson opened this issue Oct 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@vladjohnson
Copy link

Describe the bug
Pandera's DataFrameSchema does not properly handle datetime with timezone (datetime64[ns, UTC]) when using Pendulum's datetime. When applying Pandera checks with timezone-aware datetime indexes, it raises a pandera.errors.SchemaError, despite the data type being correctly defined as datetime64[ns, UTC].

Error message:
pandera.errors.SchemaError: expected series 'None' to have type datetime64[ns, UTC], got datetime64[ns, UTC]

  • I have checked that this issue has not already been reported.

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandera as pa
import pandas as pd
import pendulum

# Create a sample dataframe
data = {
    "col1": [1.0, 2.0, 3.0],
}
index = pd.DatetimeIndex(
    [pendulum.datetime(2023, 1, 1, tz="UTC"), 
     pendulum.datetime(2023, 1, 2, tz="UTC")]
)

df = pd.DataFrame(data, index=index)

# Define the schema
schema = pa.DataFrameSchema(
    {
        ".*": pa.Column(float, regex=True, nullable=False),
    },
    index=pa.Index(dtype=pd.DatetimeTZDtype(tz="UTC")),
    unique_column_names=True,
)

# Validate the dataframe
schema.validate(df)

Expected behavior

The expected behavior is for the DataFrameSchema validation to pass without errors when using a timezone-aware datetime index (datetime64[ns, UTC]), when utilizing Pendulum's datetime objects.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Browser: Chrome
  • Version: pandera==0.20.4
@vladjohnson vladjohnson added the bug Something isn't working label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant