8000 Convert to compatible NumPy dtype for MaskedArray to_numpy by phofl · Pull Request #55058 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Convert to compatible NumPy dtype for MaskedArray to_numpy #55058

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

Merged
merged 18 commits into from
Dec 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into to_numpy_ea
# Conflicts:
#	doc/source/whatsnew/v2.2.0.rst
  • Loading branch information
phofl committed Nov 29, 2023
commit b39c72995107771e339ae07065417f824359f568
64 changes: 32 additions & 32 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,7 @@ including other versions of pandas.
Enhancements
~~~~~~~~~~~~

.. _whatsnew_220.enhancements.to_numpy_ea:

ExtensionArray.to_numpy converts to suitable NumPy dtype
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:meth:`ExtensionArray.to_numpy`` will now convert to a suitable NumPy dtype instead
of ``object`` dtype for nullable extension dtypes.

*Old behavior:*

.. code-block:: ipython

In [1]: ser = pd.Series([1, 2, 3], dtype="Int64")
In [2]: ser.to_numpy()
Out[2]: array([1, 2, 3], dtype=object)

*New behavior:*

.. ipython:: python

ser = pd.Series([1, 2, 3], dtype="Int64")
ser.to_numpy()

The NumPy dtype is determined as follows:

- float dtypes are cast to NumPy floats
- integer dtypes without missing values are cast to NumPy integer dtypes
- integer dtypes with missing values are cast to NumPy float dtypes and ``NaN`` is used as missing value indicator
- boolean dtypes without missing values are cast to NumPy bool dtype
- boolean dtypes with missing values keep object dtype

.. _whatsnew_220.enhancements.calamine:
.. _whatsnew_220.enhancements.adbc_support:

ADBC Driver support in to_sql and read_sql
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -136,6 +105,37 @@ For a full list of ADBC drivers and their development status, see the `ADBC Driv
Implementation Status <https://arrow.apache.org/adbc/current/driver/status.html>`_
documentation.

.. _whatsnew_220.enhancements.to_numpy_ea:

ExtensionArray.to_numpy converts to suitable NumPy dtype
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:meth:`ExtensionArray.to_numpy`` will now convert to a suitable NumPy dtype instead
of ``object`` dtype for nullable extension dtypes.

*Old behavior:*

.. code-block:: ipython

In [1]: ser = pd.Series([1, 2, 3], dtype="Int64")
In [2]: ser.to_numpy()
Out[2]: array([1, 2, 3], dtype=object)

*New behavior:*

.. ipython:: python

ser = pd.Series([1, 2, 3], dtype="Int64")
ser.to_numpy()

The NumPy dtype is determined as follows:

- float dtypes are cast to NumPy floats
- integer dtypes without missing values are cast to NumPy integer dtypes
- integer dtypes with missing values are cast to NumPy float dtypes and ``NaN`` is used as missing value indicator
- boolean dtypes without missing values are cast to NumPy bool dtype
- boolean dtypes with missing values keep object dtype

.. _whatsnew_220.enhancements.struct_accessor:

Series.struct accessor to with PyArrow structured data
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0