Skip to content

Commit

Permalink
ENH: add integer-na support via an ExtensionArray
Browse files Browse the repository at this point in the history
closes #20700
  • Loading branch information
jreback committed May 24, 2018
1 parent 05ee2d7 commit 97b01e4
Show file tree
Hide file tree
Showing 5 changed files with 952 additions and 0 deletions.
48 changes: 48 additions & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,54 @@ v0.24.0
New features
~~~~~~~~~~~~

Integer NA Support
^^^^^^^^^^^^^^^^^^

TODO(update docs)
Pandas has gained the ability to hold integer dtypes with missing values. This long requested feature is enable thru the use of ``ExtensionTypes`` . Here is an example of usage.

We can construct a ``Series`` with the specified dtype. The dtype string ``Int64`` is a pandas ``ExtensionDtype``. Specifying an list or array using the traditional missing value
marker of ``np.nan`` will infer to integer dtype. The display of the ``Series`` will also use the ``NaN`` to indicate missing values in string outputs.

.. ipython:: python

s = pd.Series([1, 2, np.nan], dtype='Int64')
s


Operations on these dtypes will propagate ``NaN`` as other pandas operations.

.. ipython:: python

# arithmetic
s + 1

# comparison
s == 1

# indexing
s.iloc[1:3]

# operate with other dtypes
s + s.iloc[1:3]

These dtypes can operate as part of ``DataFrames`` as well.

.. ipython:: python

df = pd.DataFrame({'A': s, 'B': [1, 2, 3], 'C': list('aab')})
df
df.dtypes


These dtypes can be merged & reshaped & casted as well.

.. ipython:: python

pd.concat([df[['A']], df[['B', 'C']]], axis=1).dtypes
df['A'].astype(float)


.. _whatsnew_0240.enhancements.other:

Other Enhancements
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/arrays/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
from .base import ExtensionArray # noqa
from .categorical import Categorical # noqa
from .integer import ( # noqa
Int8Array, Int16Array, Int32Array, Int64Array,
UInt8Array, UInt16Array, UInt32Array, UInt64Array,
to_integer_array)
Loading

0 comments on commit 97b01e4

Please sign in to comment.