If I modify the README.md example to add a logger to log the validation error then that error is printed twice, e.g.,
$ python teset.py
2025-06-25 14:06:09,963 - simple_example - ERROR - Validation failed!
ERROR:simple_example:Validation failed!
That output was generated by
import logging
import pandas as pd
from pydantic import BaseModel
from pydantic.types import StrictInt
from pandantic import Pandantic
# create logger - https://docs.python.org/3/howto/logging.html#logging-advanced-tutorial
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
# Define your schema using Pydantic BaseModel
class DataFrameSchema(BaseModel):
"""Example schema for testing."""
example_str: str
example_int: StrictInt
# Create a validator instance
validator = Pandantic(schema=DataFrameSchema)
# Example DataFrame with some invalid data
df_invalid = pd.DataFrame(
data={
"example_str": ["foo", "bar", 1], # Last value is invalid (int instead of str)
"example_int": ["1", 2, 3.0], # First and last values are invalid (str and float)
}
)
# Validate with error raising
try:
validator.validate(dataframe=df_invalid, errors="raise")
except ValueError:
logger.error("Validation failed!")
I think the double error message comes from the Pandas validator in
|
logging.debug("Amount of available cores: %s", os.cpu_count()) |
and could be mitigated by instead using logging the same way the Pandas plugin works with
|
logger = logging.getLogger(__name__) |
and calling
logger.debug instead of
logging.debug, etc.
If I modify the
README.mdexample to add a logger to log the validation error then that error is printed twice, e.g.,That output was generated by
I think the double error message comes from the Pandas validator in
pandantic/src/pandantic/validators/pandas.py
Line 63 in 59732ed
pandantic/src/pandantic/plugins/pandas.py
Line 23 in 59732ed
logger.debuginstead oflogging.debug, etc.