Skip to content

Conversation

@MarcoGorelli
Copy link
Member

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

@MarcoGorelli MarcoGorelli force-pushed the more-extensionarray branch 2 times, most recently from f64cbef to 54ebfc3 Compare October 20, 2025 12:06
@MarcoGorelli MarcoGorelli marked this pull request as ready for review October 20, 2025 12:24
Copy link
Contributor

@cmp0xff cmp0xff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • It adds types to .astype, .fillna, .view and .searchsorted with tests (addresses #1317)
  • It also adds Any to .tolist and adds default values ._reduce
  • Just minor comment, otherwise good to go

@overload
def astype(self, dtype: np.dtype, copy: bool = True) -> np.ndarray: ...
@overload
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try

Suggested change
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ...
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> Self: ...

because I guess you can't convert an IntervalArray to an IntegerArray by .astype. But I understand that this is unspecified in the docs, so keeping -> ExtensionArray is also fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it possible though?

In [34]: arr = pd.Series([1.]).array

In [35]: arr
Out[35]:
<NumpyExtensionArray>
[1.0]
Length: 1, dtype: float64

In [36]: arr.astype('Int64')
Out[36]:
<IntegerArray>
[1]
Length: 1, dtype: Int64

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, my assumption was not correct.

Copy link
Contributor

@cmp0xff cmp0xff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I hope one day we can get rid of -> ExtensionArray, but we can leave it for another project. Thank you @MarcoGorelli !

@overload
def astype(self, dtype: np.dtype, copy: bool = True) -> np.ndarray: ...
@overload
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, my assumption was not correct.

@cmp0xff cmp0xff merged commit 6c5d850 into pandas-dev:main Oct 20, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants