-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: Assorted cleanups #30260
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: Assorted cleanups #30260
Changes from all commits
24e2ddd
b16b4cc
ec7ddc5
f6d32d2
c4d90a2
3002f1f
069e966
ec6125a
a9b52ae
45b7ac3
9801a75
0a64173
1e11396
e40f054
009c893
17fa54b
74f31f2
6ca4461
80d32e1
41a3f1a
554cb0d
560a6ef
c6cd691
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 |
---|---|---|
|
@@ -244,13 +244,13 @@ def maybe_upcast_putmask(result: np.ndarray, mask: np.ndarray, other): | |
necessary. | ||
mask : boolean ndarray | ||
other : scalar | ||
The source value | ||
The source value. | ||
|
||
Returns | ||
------- | ||
result : ndarray | ||
changed : boolean | ||
Set to true if the result array was upcasted | ||
changed : bool | ||
Set to true if the result array was upcasted. | ||
|
||
Examples | ||
-------- | ||
|
@@ -337,6 +337,21 @@ def changeit(): | |
|
||
|
||
def maybe_promote(dtype, fill_value=np.nan): | ||
""" | ||
Find the minimal dtype that can hold both the given dtype and fill_value. | ||
|
||
Parameters | ||
---------- | ||
dtype : np.dtype or ExtensionDtype | ||
fill_value : scalar, default np.nan | ||
|
||
Returns | ||
------- | ||
dtype | ||
Upcasted from dtype argument if necessary. | ||
fill_value | ||
Upcasted from fill_value argument if necessary. | ||
""" | ||
if not is_scalar(fill_value) and not is_object_dtype(dtype): | ||
# with object dtype there is nothing to promote, and the user can | ||
# pass pretty much any weird fill_value they like | ||
|
@@ -592,11 +607,11 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False): | |
|
||
def infer_dtype_from_array(arr, pandas_dtype: bool = False): | ||
""" | ||
Infer the dtype from a scalar or array. | ||
Infer the dtype from an array. | ||
|
||
Parameters | ||
---------- | ||
arr : scalar or array | ||
arr : array | ||
pandas_dtype : bool, default False | ||
whether to infer dtype including pandas extension types. | ||
If False, array belongs to pandas extension types | ||
|
@@ -622,7 +637,6 @@ def infer_dtype_from_array(arr, pandas_dtype: bool = False): | |
|
||
>>> infer_dtype_from_array([1, '1']) | ||
(numpy.object_, [1, '1']) | ||
|
||
""" | ||
|
||
if isinstance(arr, np.ndarray): | ||
|
@@ -686,10 +700,12 @@ def maybe_upcast(values, fill_value=np.nan, dtype=None, copy: bool = False): | |
|
||
Parameters | ||
---------- | ||
values : the ndarray that we want to maybe upcast | ||
values : ndarray or ExtensionArray | ||
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. ideally type these at some point |
||
The array that we want to maybe upcast. | ||
fill_value : what we want to fill with | ||
dtype : if None, then use the dtype of the values, else coerce to this type | ||
copy : if True always make a copy even if no upcast is required | ||
copy : bool, default True | ||
If True always make a copy even if no upcast is required. | ||
""" | ||
if not is_scalar(fill_value) and not is_object_dtype(values.dtype): | ||
# We allow arbitrary fill values for object dtype | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,10 +74,12 @@ def cat_core(list_of_columns: List, sep: str): | |
""" | ||
if sep == "": | ||
# no need to interleave sep if it is empty | ||
return np.sum(list_of_columns, axis=0) | ||
arr_of_cols = np.asarray(list_of_columns, dtype=object) | ||
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. What is this cleaning up? 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. this is for when numpy re-institutes the make-object-explicit thing from #30035. 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 think should hold off on these changes then until that comes back 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. they reverted it specifically to give downstream time to update without breaking CIs 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. great this is good |
||
return np.sum(arr_of_cols, axis=0) | ||
list_with_sep = [sep] * (2 * len(list_of_columns) - 1) | ||
list_with_sep[::2] = list_of_columns | ||
return np.sum(list_with_sep, axis=0) | ||
arr_with_sep = np.asarray(list_with_sep) | ||
return np.sum(arr_with_sep, axis=0) | ||
|
||
|
||
def cat_safe(list_of_columns: List, sep: str): | ||
|
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.
should type at some point