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

Small fixes for Category #1074

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

koalp
Copy link

@koalp koalp commented Jan 20, 2023

This PR solves issue with the Category type.

Makes numpy_pandas_coercible return a Series of bool

It solves #1073

More informative error message when coercing category

#931

The error message would now be

pandera.errors.SchemaError: 
Error while coercing 'category' to type CategoricalDtype(categories=[1, 2], ordered=False): 
Could not coerce <class 'pandas.core.series.Series'> data_container into type category:

instead of

pandera.errors.SchemaError: 
Error while coercing 'category' to type category:
Could not coerce <class 'pandas.core.series.Series'> data_container into type category:
  • Should a custom f-string be used instead of repr(self.dtype) ? As repr is multiline whene there is too much categories, it may be better to use a oneline string.

closes

closes #1073
closes #931

@koalp koalp marked this pull request as draft January 20, 2023 17:36
When using numpy_pandas_coercible on Series of Categorical, it was
returning a Categorical Series instead of a bool series.

It has been fixed by enforcing the return dtype.

Signed-off-by: koalp <[email protected]>
Errors when using Category were a bit missleading.

A __str__ method for Category has been added to make it more readable.

Signed-off-by: koalp <[email protected]>
@koalp koalp force-pushed the fix/coerce-categorical-error branch from cbedb73 to ba782c2 Compare January 20, 2023 18:07
@cosmicBboy
Copy link
Collaborator

hi @koalp thanks for the PR! This is blocked by a big pandera internals re-write: #913, I'll ping you here once that's merged, as the changes you've added will need to be ported over to the new internals.

@cosmicBboy cosmicBboy marked this pull request as ready for review April 15, 2024 14:58
@cosmicBboy cosmicBboy closed this Apr 15, 2024
@cosmicBboy cosmicBboy reopened this Apr 15, 2024
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 this pull request may close these issues.

error when failing to coerce Category is wrong Non-informative message in case of categorical data
2 participants