You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As silly as the title is, I think it's about the most condensed way to describe my problem.
If I have a Pandas dataframe
And I use a Pandera DataFrameModel class to validate said dataframe
And I try to log the exception
Then the script will never stop (or at least run beyond the 5 minutes I was willing to wait)
For your ease, I already prepared a minimal example that triggers this behavior, and I come bringing a uv script:
Run this with uv run --script script.py, if you save this as script.py. Normally I wouldn't do this, but I know you're a fan of uv, as I am, so this should make both our lives easier 😉.
# /// script# requires-python = ">=3.11" # python version does not seem to matter (3.7, 3.11 and 3.13 tested)# dependencies = [# "pandas>=2.2.0", # 2.2.0 minimal version# "pandera>=0.20.0", # 0.20.0 minimal version# "rich>=13.9.4", # if you disable `rich`, it'll run as expected, or:# "structlog>=24.4.0", # version 21.1.0 works as well, anything after it breaks.# ]# # run this file with "uv run --script script.py"# ///print("1. loading imports")
importpandasaspdimportpanderaaspafrompandera.typingimportSeriesfrompandera.errorsimportSchemaErrorfromstructlog.stdlibimportget_loggerprint("2. loading logger")
logger=get_logger(__name__)
print("3. loading schema")
classMySchema(pa.DataFrameModel):
my_floats: Series[float] =pa.Field(
alias="my_floats", check_name=True, nullable=False
)
classConfig:
coerce=Trueprint("4. loading dict")
MY_DICT= {
"my_floats": {
1: "tHiS iS nOt A fLoAt",
},
}
print("5. dict to dataframe")
df=pd.DataFrame.from_dict(MY_DICT)
try:
print("6. validation")
MySchema.validate(df)
exceptSchemaErrorasschema_error:
print(
"7. logging the exception (cancel the script after 30 seconds, as it'll run forever)"
)
logger.exception("ingestion-validation-unsuccessful")
print("8. you'll never reach this point")
raiseschema_error
The text was updated successfully, but these errors were encountered:
As silly as the title is, I think it's about the most condensed way to describe my problem.
Then the script will never stop (or at least run beyond the 5 minutes I was willing to wait)
For your ease, I already prepared a minimal example that triggers this behavior, and I come bringing a
uv
script:Run this with
uv run --script script.py
, if you save this asscript.py
. Normally I wouldn't do this, but I know you're a fan ofuv
, as I am, so this should make both our lives easier 😉.The text was updated successfully, but these errors were encountered: