-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
REF: Use np.result_type instead of np.find_common_type #53343
Changes from all commits
1f52516
7081bc1
cfb0522
a6d9ad3
cfe1486
a0f176f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1328,6 +1328,32 @@ def common_dtype_categorical_compat( | |
return dtype | ||
|
||
|
||
def np_find_common_type(*dtypes: np.dtype) -> np.dtype: | ||
""" | ||
np.find_common_type implementation pre-1.25 deprecation using np.result_type | ||
https://github.com/pandas-dev/pandas/pull/49569#issuecomment-1308300065 | ||
|
||
Parameters | ||
---------- | ||
dtypes : np.dtypes | ||
|
||
Returns | ||
------- | ||
np.dtype | ||
""" | ||
try: | ||
common_dtype = np.result_type(*dtypes) | ||
if common_dtype.kind in "mMSU": | ||
# NumPy promotion currently (1.25) misbehaves for for times and strings, | ||
# so fall back to object (find_common_dtype did unless there | ||
# was only one dtype) | ||
common_dtype = np.dtype("O") | ||
|
||
except TypeError: | ||
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. can you give an example of what gets here? 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.
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. AFAICT pretty much anything that would resolve to |
||
common_dtype = np.dtype("O") | ||
return common_dtype | ||
|
||
|
||
@overload | ||
def find_common_type(types: list[np.dtype]) -> np.dtype: | ||
... | ||
|
@@ -1395,7 +1421,7 @@ def find_common_type(types): | |
if t.kind in "iufc": | ||
return np.dtype("object") | ||
|
||
return np.find_common_type(types, []) | ||
return np_find_common_type(*types) | ||
|
||
|
||
def construct_2d_arraylike_from_scalar( | ||
|
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.
is there some numpy version at which we can remove this check?
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.
Not sure cc @seberg any thoughts?
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 have a PR that would fix it, so I hope next release this will happen. That was the PR which get stuck a bit on the discussion of what
==
should do.