-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Fix categorical from codes nan 21767 #21775
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
Changes from 1 commit
355ffd7
acb00db
c625ebb
93659e8
a880024
b6e173b
69fb0d5
bab4c76
c41bf01
3d955d1
b8d4b83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -640,7 +640,7 @@ def from_codes(cls, codes, categories, ordered=False): | |
err = False | ||
codes = icodes | ||
warn("float codes will be disallowed in the future", | ||
FutureWarning) | ||
FutureWarning, stacklevel=2) | ||
else: | ||
err = True | ||
if err: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of using and then just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if not is_integer_dtype(codes):
msg = "codes need to be array-like integers"
if is_float_dtype(codes):
icodes = codes.astype('i8')
if (icodes == codes).all():
err = False
codes = icodes
warn("float codes will be disallowed in the future",
FutureWarning)
else:
raise ValueError(msg)
else:
raise ValueError(msg) is that what you want? That doesn't read easier to me, but I can change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -480,7 +480,7 @@ def test_from_codes_with_float(self): | |
codes = [1.0, 2.0, 0] # integer, but in float dtype | ||
categories = ['a', 'b', 'c'] | ||
|
||
with tm.assert_produces_warning(FutureWarning, ch 7895 eck_stacklevel=False): | ||
with tm.assert_produces_warning(FutureWarning): | ||
Categorical.from_codes(codes, categories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, can you assert the results of the float converted to integer here (as it just warns but doesn't raise). |
||
|
||
codes = [1.1, 2.0, 0] # non-integer | ||
|
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.
Say that in the future this will raise a
ValueError
.