-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Deprecated fastpath parameter in Categorial constructor #17889
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
Conversation
Hello @kaichogami! Thanks for updating the PR.
Comment last updated on November 13, 2017 at 12:27 Hours UTC |
@@ -563,7 +566,7 @@ def _from_inferred_categories(cls, inferred_categories, inferred_codes, | |||
dtype = CategoricalDtype(cats, ordered=False) | |||
codes = inferred_codes | |||
|
|||
return cls(codes, dtype=dtype, fastpath=True) | |||
return cls(codes, 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.
I am quite confused on what should be done for the fastpath parameters used in class method's to create a new Categorial
. Should I replace them with dtype
or let the __init__
handle CategorialDtype
construction?
Thanks @kaichogami! I didn't quite understand what fastpath was doing earlier. It seems to only be valid when Ok, so, we'll want to modify def from_codes(cls, codes, categories, ordered=None, dtype=None):
... We'll do the validation of def validate_dtype(values=None, categories=None, ordered=None, dtype=None):
# Ways of specifying the dtype (prioritized ordered)
# 1. dtype is a CategoricalDtype
# a.) with known categories, use dtype.categories
# b.) else with Categorical values, use values.dtype
# c.) else, infer from values
# d.) specifying dtype=CategoricalDtype and categories is an error
# 2. dtype is a string 'category'
# a.) use categories, ordered
# b.) use values.dtype
# c.) infer from values
# 3. dtype is None
# a.) use categories, ordered
# b.) use values.dtype
# c.) infer from values
if dtype is not None:
if isinstance(dtype, compat.string_types):
if dtype == 'category':
dtype = CategoricalDtype(categories, ordered)
else:
msg = "Unknown `dtype` {dtype}"
raise ValueError(msg.format(dtype=dtype))
elif categories is not None or ordered is not None:
raise ValueError("Cannot specify both `dtype` and `categories`"
" or `ordered`.")
categories = dtype.categories
ordered = dtype.ordered
elif is_categorical(values):
dtype = values.dtype._from_categorical_dtype(values.dtype,
categories, ordered)
else:
dtype = CategoricalDtype(categories, ordered)
return categories, ordered, dtype And use that in both Then, in self = cls.__new__(cls)
self._codes = coerce_indexer_dtype(codes, dtype.categories)
self._dtype = dtype
return self I think that'll work. Then, anywhere you see a |
Yes, it does. I will go change it as soon as I can. Thanks for the feedback! 😄 |
Hi, I am a bit busy so if its something important somebody else can take it over, otherwise I will do it by next week. Thank you. |
No rush on this. |
can you rebase |
f76806c
to
92303ec
Compare
closing as stale, if you want to work on this, pls ping. |
Hello everyone!
I am new to Pandas developer community and your feedback would help me a lot. Thank you!