Skip to content

Commit 6fc19f9

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

File tree

15 files changed

+639
-18
lines changed

15 files changed

+639
-18
lines changed

pandas/core/algorithms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _reconstruct_data(values, dtype, original):
154154
"""
155155
from pandas import Index
156156
if is_extension_array_dtype(dtype):
157-
pass
157+
values = dtype.array_type._from_sequence(values)
158158
elif is_datetime64tz_dtype(dtype) or is_period_dtype(dtype):
159159
values = Index(original)._shallow_copy(values, name=None)
160160
elif is_bool_dtype(dtype):
@@ -705,7 +705,7 @@ def value_counts(values, sort=True, ascending=False, normalize=False,
705705

706706
else:
707707

708-
if is_categorical_dtype(values) or is_sparse(values):
708+
if is_extension_array_dtype(values) or is_sparse(values):
709709

710710
# handle Categorical and sparse,
711711
result = Series(values)._values.value_counts(dropna=dropna)

pandas/core/arrays/base.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,16 @@ class ExtensionArray(object):
8282
# Constructors
8383
# ------------------------------------------------------------------------
8484
@classmethod
85-
def _from_sequence(cls, scalars):
85+
def _from_sequence(cls, scalars, copy=False):
8686
"""Construct a new ExtensionArray from a sequence of scalars.
8787
8888
Parameters
8989
----------
9090
scalars : Sequence
9191
Each element will be an instance of the scalar type for this
9292
array, ``cls.dtype.type``.
93+
copy : boolean, default True
94+
if True, copy the underlying data
9395
Returns
9496
-------
9597
ExtensionArray
@@ -567,6 +569,34 @@ def copy(self, deep=False):
567569
"""
568570
raise AbstractMethodError(self)
569571

572+
def append(self, other):
573+
"""
574+
Append a collection of Arrays together
575+
576+
Parameters
577+
----------
578+
other : ExtenionArray or list/tuple of ExtenionArrays
579+
580+
Returns
581+
-------
582+
appended : ExtensionArray
583+
"""
584+
585+
to_concat = [self]
586+
cls = self.__class__
587+
588+
if isinstance(other, (list, tuple)):
589+
to_concat = to_concat + list(other)
590+
else:
591+
to_concat.append(other)
592+
593+
for obj in to_concat:
594+
if not isinstance(obj, cls):
595+
raise TypeError('all inputs must be of type {}'.format(
596+
cls.__name__))
597+
598+
return cls._concat_same_type(to_concat)
599+
570600
# ------------------------------------------------------------------------
571601
# Block-related methods
572602
# ------------------------------------------------------------------------

pandas/core/arrays/categorical.py

+4
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,10 @@ def isin(self, values):
23432343
return algorithms.isin(self.codes, code_values)
23442344

23452345

2346+
# inform the Dtype about us
2347+
CategoricalDtype.array_type = Categorical
2348+
2349+
23462350
# The Series.cat accessor
23472351

23482352

0 commit comments

Comments
 (0)