Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> s = pd.Series([0, None, 4, 5], dtype="u1[pyarrow]")
>>> s
0 0
1 <NA>
2 4
3 5
dtype: uint8[pyarrow]
>>> s.isna()
0 False
1 True
2 False
3 False
dtype: bool
Issue Description
s.isna().dtype
is BoolDType
(bool
) instead of ArrowDtype(pa.bool_())
(bool[pyarrow]
)
Expected Behavior
>>> s.isna()
0 False
1 True
2 False
3 False
dtype: bool[pyarrow]
Installed Versions
Comment From: loicdiridollou
Hey @thesword53,
I realized that issue also affected something I am working on so I went down the rabbit hole and it seems like what is happening is that the Series
gets cast to a np.ndarray
then the is isna
operation gets applied and when they rebuild the Series
object, we lose the original type (pyarrow) and it seems like it just rebuilds without any assumption of type (as we pass an np.ndarray
of bool it just set the type of the Series to bool
and not bool[pyarrow]
).
https://github.com/pandas-dev/pandas/blob/aa134bb9495754271f54a9b887ffcd85fca9d956/pandas/core/dtypes/missing.py#L208-L210
This also affects if you create a Dataframe
where the type of the column was originally uint8[pyarrow]
and it gets cast into bool
and not bool[pyarrow]
.
Comment From: KevsterAmp
I'd like to work on this
Comment From: KevsterAmp
take
Comment From: KevsterAmp
take
Comment From: KevsterAmp
take
Comment From: KevsterAmp
Can't seem to assign the issue to myself, but I'll be opening a PR for this in a bit. Thanks @loicdiridollou for further investigating
Comment From: KevsterAmp
Take
Comment From: rhshadrach
Ref: https://github.com/pandas-dev/pandas/pull/59436#pullrequestreview-2225761630
Comment From: WillAyd
This is another good issue to track for PDEP-13 https://github.com/pandas-dev/pandas/pull/58455
Comment From: jbrockmendel
I think I expect a numpy bool here. We pass it as a mask in a bunch of places