Skip to content

Commit accbdcc

Browse files
committed
ENH: add integer-na support via an ExtensionArray
closes pandas-dev#20700
1 parent ba74be4 commit accbdcc

File tree

5 files changed

+952
-0
lines changed

5 files changed

+952
-0
lines changed

doc/source/whatsnew/v0.24.0.txt

+48
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,54 @@ v0.24.0
88
New features
99
~~~~~~~~~~~~
1010

11+
Integer NA Support
12+
^^^^^^^^^^^^^^^^^^
13+
14+
TODO(update docs)
15+
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.
16+
17+
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
18+
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.
19+
20+
.. ipython:: python
21+
22+
s = pd.Series([1, 2, np.nan], dtype='Int64')
23+
s
24+
25+
26+
Operations on these dtypes will propagate ``NaN`` as other pandas operations.
27+
28+
.. ipython:: python
29+
30+
# arithmetic
31+
s + 1
32+
33+
# comparison
34+
s == 1
35+
36+
# indexing
37+
s.iloc[1:3]
38+
39+
# operate with other dtypes
40+
s + s.iloc[1:3]
41+
42+
These dtypes can operate as part of ``DataFrames`` as well.
43+
44+
.. ipython:: python
45+
46+
df = pd.DataFrame({'A': s, 'B': [1, 2, 3], 'C': list('aab')})
47+
df
48+
df.dtypes
49+
50+
51+
These dtypes can be merged & reshaped & casted as well.
52+
53+
.. ipython:: python
54+
55+
pd.concat([df[['A']], df[['B', 'C']]], axis=1).dtypes
56+
df['A'].astype(float)
57+
58+
1159
.. _whatsnew_0240.enhancements.other:
1260

1361
Other Enhancements

pandas/core/arrays/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
from .base import ExtensionArray # noqa
22
from .categorical import Categorical # noqa
3+
from .integer import ( # noqa
4+
Int8Array, Int16Array, Int32Array, Int64Array,
5+
UInt8Array, UInt16Array, UInt32Array, UInt64Array,
6+
to_integer_array)

0 commit comments

Comments
 (0)