-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: various related to numeric indexes #41615
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
CLN: various related to numeric indexes #41615
Conversation
else: | ||
raise NotImplementedError(f"wrong dtype {dtype}") | ||
|
||
return Index(values, dtype=dtype, name=name) |
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.
In #41153 we'll only need to change this to return NumericIndex(values, dtype=dtype, name=name)
after this.
@@ -292,21 +296,40 @@ def makeBoolIndex(k=10, name=None): | |||
return Index([False, True] + [False] * (k - 2), name=name) | |||
|
|||
|
|||
def makeNumericIndex(k=10, name=None, *, dtype): | |||
dtype = pandas_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.
do we expect non-numpy dtypes here?
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’ve added an assert for that here.
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.
my idea was to just use dtype = np.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.
>>> np.dtype("Int8") # capital Int
DeprecationWarning: Numeric-style type codes are deprecated and will result in an error in the future.
np.dtype("Int8")
dtype('int8')
So I think we should hold on this until the above raises IMO.
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 will not ever raise as these are pandas dtypes
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.
@jbrockmendel raises a valid point; if u r expecting only numpy dtypes then why are pandas dtypes passed?
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 will not ever raise as these are pandas dtypes
assert isinstance(dtype, np.dtype)
on line 304 ensures that it will raise if it is a pandas dtype.
if u r expecting only numpy dtypes then why are pandas dtypes passed?
I'm not intending to pass pandas dtypes here, but I'm using pandas_dtype
to avoid an ambiguity: The string "Int64"
in Pandas means Int64Dtype
, but in numpy it means np.int64
. So by using dtype = pandas_dtype(dtype)
, then an assert(dtype, np.dtype)
, we ensure the correct dtype..
pandas/_testing/__init__.py
Outdated
|
||
if dtype.kind == "i": | ||
values = list(range(k)) | ||
elif dtype.kind == "u": |
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.
can u use np.arrange in these i and u cases
or make the i and u cases the same structure ; they are completely different now
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've made a better version.
6d672ba
to
c5dbfa4
Compare
c5dbfa4
to
02f54b2
Compare
Ping? Np.dtype("Int64") doesn’t raise, so I do think using pandas_dtype + asserting a numpy dtype is better than np.dtype. |
thanks @topper-123 |
A few bits to make #41153 smaller.
Also fixes an issue with the current implementation of NumericIndex._engine_type:
The implementation currently uses
self.dtype.type
, which is a problem when we are given platform-specific dtypes, e.g.np.intc
.For example:
So the _engine_type dict should use np.dtype(np.int64) etc., so avoid such problems.