Skip to content

DEPR: Categorical with values not present in categories #62142

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

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

Conversation

jbrockmendel
Copy link
Member

Comment on lines +545 to +550
warnings.filterwarnings(
"ignore",
"Constructing a Categorical with a dtype and values",
FutureWarning,
)
res = cls._from_sequence(scalars, dtype=dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here once the deprecation is enforced?

Comment on lines 1181 to +1182
codes = recode_for_categories(
cat.codes, cat.categories, new_dtype.categories, copy=False
cat.codes, cat.categories, new_dtype.categories, copy=False, warn=False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the deprecation is enforced, do we still need to pass the flag on whether to allow values outside the categories?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the flag will become a "should we raise" flag, and will still be needed bc the answer will be "no" for set_categories

@@ -258,6 +258,12 @@ def _is_dtype_compat(self, other: Index) -> Categorical:
else:
values = other

codes = self.categories.get_indexer(values)
if ((codes == -1) & ~values.isna()).any():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the check on L269 with this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think not, will check and update

Comment on lines +131 to +132
# [c, None, None, dtype2, dtype2],
# [c, ["x", "y"], False, None, dtype2],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove or uncomment/update?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, will update

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.

API: astype method fails to raise errors for category data type API: Categorical constructor with dtype raise instead of casting to NA
2 participants