-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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
base: main
Are you sure you want to change the base?
Conversation
warnings.filterwarnings( | ||
"ignore", | ||
"Constructing a Categorical with a dtype and values", | ||
FutureWarning, | ||
) | ||
res = cls._from_sequence(scalars, dtype=dtype) |
There was a problem hiding this comment.
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?
codes = recode_for_categories( | ||
cat.codes, cat.categories, new_dtype.categories, copy=False | ||
cat.codes, cat.categories, new_dtype.categories, copy=False, warn=False |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
# [c, None, None, dtype2, dtype2], | ||
# [c, ["x", "y"], False, None, dtype2], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or uncomment/update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, will update
astype
method fails to raise errors forcategory
data type #59899doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.