-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Makes NumericIndex constructor dtype aware #29529
Conversation
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.
Thanks! Approach looks good. Can you add an entry to the 1.0 whatsnew under the "Bug Fixes - Numeric" subsection (around line 339)?
pandas/core/indexes/numeric.py
Outdated
@@ -57,7 +57,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, fastpath=None): | |||
return cls._simple_new(data, name=name) | |||
|
|||
# is_scalar, generators handled in coerce_to_ndarray | |||
data = cls._coerce_to_ndarray(data) | |||
data = cls._coerce_to_ndarray(data, 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 don't think this should rely on dtype
being explicitly passed in (it's None
by default) so maybe make this dtype=self._dtype
for now since the dtype
parameter isn't being validated.
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.
This initially made sense to me.
However, numpy
seems to complicate this suggestion since it'll cast input if dtype
is explicitly passed:
In [1]: import numpy as np
...: np.__version__
Out[1]: '1.17.3'
In [2]: np.array([1, "2"])
...:
Out[2]: array(['1', '2'], dtype='<U21')
In [3]: np.array(["1", "2"])
...:
Out[3]: array(['1', '2'], dtype='<U1')
In [4]: np.array(["1", "2"], dtype='int')
Out[4]: array([1, 2])
This test suggests that pandas
keeps the same behavior. With 458c25e, I tried to check the type of elements. The side effect of that is consuming iterators, leading to the current errors.
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 numpy
behavior I report above is brought up here but not acted on.
I added the what's new entry but I must admit I haven't yet managed to set up building docs in a performant way. I'll check that soon and let you know. |
The failing tast was this. Now there are more of them :) Perhaps it's too late now, I'll take a fresh look over the weekend. I had some questions as well...
|
Hello @oguzhanogreden! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-11-17 21:30:54 UTC |
Sorry about a bit of back and forth here. Finally:
|
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.
lgtm. some small requests. ping on green.
# is_scalar, generators handled in coerce_to_ndarray | ||
data = cls._coerce_to_ndarray(data) | ||
# Coerce to ndarray if not already ndarray or Index | ||
if not isinstance(data, (np.ndarray, Index)): |
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.
hah, this is what we had quite some time ago. thanks
thanks @oguzhanogreden |
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.
Sorry, I've been a little behind on reviewing and noticed a couple small things that could be done as a follow up. Edit: Nevermind, this can be ignored.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff