-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: general concat with ExtensionArrays through find_common_type #33607
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 all commits
3464e95
b1d9d68
bb398e7
83fdc91
7f2ac2a
d0f90de
2d5fcb0
a68206b
fc98b65
b072591
91c984a
2a2b9d5
8893165
e19e3ef
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 |
---|---|---|
|
@@ -2296,9 +2296,9 @@ def _can_hold_na(self): | |
|
||
@classmethod | ||
def _concat_same_type(self, to_concat): | ||
from pandas.core.dtypes.concat import concat_categorical | ||
from pandas.core.dtypes.concat import union_categoricals | ||
|
||
return concat_categorical(to_concat) | ||
return union_categoricals(to_concat) | ||
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. IIRC only a relatively small part of the logic of concat_categorical/union_categoricals is actually needed here. I'd prefer for that to live here and for union_categoricals to call it, rather than the other way around (since union_categoricals handles a lot of cases). Could be considered orthogonally to this PR. 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.
Yes, that's indeed a good idea (union_categoricals does way much more that is all not needed 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. are you planning to update this, or is that a topic for a separate PR? |
||
|
||
def isin(self, values): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import numbers | ||
from typing import TYPE_CHECKING, Tuple, Type, Union | ||
from typing import TYPE_CHECKING, List, Optional, Tuple, Type, Union | ||
import warnings | ||
|
||
import numpy as np | ||
|
||
from pandas._libs import lib, missing as libmissing | ||
from pandas._typing import ArrayLike | ||
from pandas._typing import ArrayLike, DtypeObj | ||
from pandas.compat import set_function_name | ||
from pandas.compat.numpy import function as nv | ||
from pandas.util._decorators import cache_readonly | ||
|
@@ -96,6 +96,17 @@ def construct_array_type(cls) -> Type["IntegerArray"]: | |
""" | ||
return IntegerArray | ||
|
||
def _get_common_dtype(self, dtypes: List[DtypeObj]) -> Optional[DtypeObj]: | ||
# for now only handle other integer types | ||
if not all(isinstance(t, _IntegerDtype) for t in dtypes): | ||
return None | ||
np_dtype = np.find_common_type( | ||
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. is there a reason you are not using pandas 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. Because this are all numpy integer dtypes, so there is no need to use our version that can handle our custom logic/dtypes |
||
[t.numpy_dtype for t in dtypes], [] # type: ignore | ||
) | ||
if np.issubdtype(np_dtype, np.integer): | ||
return _dtypes[str(np_dtype)] | ||
return None | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def __from_arrow__( | ||
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"] | ||
) -> "IntegerArray": | ||
|
Uh oh!
There was an error while loading. Please reload this page.