Skip to content

Commit

Permalink
ENH: add integer-na support via an ExtensionArray
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed May 14, 2018
1 parent d43e86a commit 6fc19f9
Show file tree
Hide file tree
Showing 15 changed files with 639 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _reconstruct_data(values, dtype, original):
"""
from pandas import Index
if is_extension_array_dtype(dtype):
pass
values = dtype.array_type._from_sequence(values)
elif is_datetime64tz_dtype(dtype) or is_period_dtype(dtype):
values = Index(original)._shallow_copy(values, name=None)
elif is_bool_dtype(dtype):
Expand Down Expand Up @@ -705,7 +705,7 @@ def value_counts(values, sort=True, ascending=False, normalize=False,

else:

if is_categorical_dtype(values) or is_sparse(values):
if is_extension_array_dtype(values) or is_sparse(values):

# handle Categorical and sparse,
result = Series(values)._values.value_counts(dropna=dropna)
Expand Down
32 changes: 31 additions & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ class ExtensionArray(object):
# Constructors
# ------------------------------------------------------------------------
@classmethod
def _from_sequence(cls, scalars):
def _from_sequence(cls, scalars, copy=False):
"""Construct a new ExtensionArray from a sequence of scalars.
Parameters
----------
scalars : Sequence
Each element will be an instance of the scalar type for this
array, ``cls.dtype.type``.
copy : boolean, default True
if True, copy the underlying data
Returns
-------
ExtensionArray
Expand Down Expand Up @@ -567,6 +569,34 @@ def copy(self, deep=False):
"""
raise AbstractMethodError(self)

def append(self, other):
"""
Append a collection of Arrays together
Parameters
----------
other : ExtenionArray or list/tuple of ExtenionArrays
Returns
-------
appended : ExtensionArray
"""

to_concat = [self]
cls = self.__class__

if isinstance(other, (list, tuple)):
to_concat = to_concat + list(other)
else:
to_concat.append(other)

for obj in to_concat:
if not isinstance(obj, cls):
raise TypeError('all inputs must be of type {}'.format(
cls.__name__))

return cls._concat_same_type(to_concat)

# ------------------------------------------------------------------------
# Block-related methods
# ------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,10 @@ def isin(self, values):
return algorithms.isin(self.codes, code_values)


# inform the Dtype about us
CategoricalDtype.array_type = Categorical


# The Series.cat accessor


Expand Down
Loading

0 comments on commit 6fc19f9

Please sign in to comment.