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

get_errors allow_empty=True fails with datetime types #43

Open
sleipodin opened this issue Nov 12, 2020 · 0 comments · May be fixed by #44
Open

get_errors allow_empty=True fails with datetime types #43

sleipodin opened this issue Nov 12, 2020 · 0 comments · May be fixed by #44

Comments

@sleipodin
Copy link

sleipodin commented Nov 12, 2020

Similar to #22...

When attempting to call get_errors() with allow_empty=True on a datetime Series, the following is encountered:

Traceback (most recent call last):
  File "xxx", line 12, in <module>
    errors = validator.get_errors(series, Column('', allow_empty=True))
  File "D:\Git\PandasSchema\pandas_schema\validation.py", line 92, in get_errors
    validated = (series.str.len() > 0) & simple_validation
  File "xxx\pandas\core\generic.py", line 5135, in __getattr__
    return object.__getattribute__(self, name)
  File "xxx\pandas\core\accessor.py", line 187, in __get__
    accessor_obj = self._accessor(obj)
  File "xxx\pandas\core\strings.py", line 2100, in __init__
    self._inferred_dtype = self._validate(data)
  File "xxx\pandas\core\strings.py", line 2157, in _validate
    raise AttributeError("Can only use .str accessor with string values!")
AttributeError: Can only use .str accessor with string values!

To reproduce:

match_val = datetime.datetime(2020, 11, 1)
validator = CustomSeriesValidation(lambda s: s == match_val, 'did not match target date')
series = pd.Series(['2020-11-01'], dtype='datetime64[ns]')
errors = validator.get_errors(series, Column('', allow_empty=True))

It seems to be a quick fix at https://github.com/TMiguelT/PandasSchema/blob/master/pandas_schema/validation.py#L89. I have code and tests ready if interested.

@sleipodin sleipodin linked a pull request Nov 12, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant