Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2ef5216
REF: Define extension base classes
TomAugspurger Jan 15, 2018
57e8b0f
Updated for comments
TomAugspurger Jan 18, 2018
01bd42f
Remove metaclasses from PeriodDtype and IntervalDtype
TomAugspurger Jan 18, 2018
ce81706
Fixup form_blocks rebase
TomAugspurger Jan 18, 2018
87a70e3
Restore concat casting cat -> object
TomAugspurger Jan 18, 2018
8c61886
Remove _slice, clarify semantics around __getitem__
TomAugspurger Jan 19, 2018
cb41803
Document and use take.
TomAugspurger Jan 19, 2018
65d5a61
Clarify type, kind, init
TomAugspurger Jan 19, 2018
57c749b
Remove base
TomAugspurger Jan 19, 2018
6736b0f
API: Remove unused __iter__ and get_values
TomAugspurger Jan 21, 2018
e4acb59
API: Implement repr and str
TomAugspurger Jan 21, 2018
0e9337b
Merge remote-tracking branch 'upstream/master' into pandas-array-inte…
TomAugspurger Jan 26, 2018
df68f3b
Remove default value_counts for now
TomAugspurger Jan 26, 2018
2746a43
Fixed merge conflicts
TomAugspurger Jan 27, 2018
34d2b99
Remove implementation of construct_from_string
TomAugspurger Jan 27, 2018
a484d61
Example implementation of take
TomAugspurger Jan 27, 2018
04b2e72
Cleanup ExtensionBlock
TomAugspurger Jan 27, 2018
df0fa12
Merge remote-tracking branch 'upstream/master' into pandas-array-inte…
TomAugspurger Jan 27, 2018
e778053
Pass through ndim
TomAugspurger Jan 27, 2018
d15a722
Use series._values
TomAugspurger Jan 27, 2018
b5f736d
Removed repr, updated take doc
TomAugspurger Jan 27, 2018
240e8f6
Various cleanups
TomAugspurger Jan 28, 2018
f9b0b49
Handle get_values, to_dense, is_view
TomAugspurger Jan 28, 2018
7913186
Docs
TomAugspurger Jan 30, 2018
df18c3b
Remove is_extension, is_bool
TomAugspurger Jan 30, 2018
ab2f045
Sparse formatter
TomAugspurger Jan 30, 2018
520876f
Revert "Sparse formatter"
TomAugspurger Jan 30, 2018
4dfa39c
Unbox SparseSeries
TomAugspurger Jan 30, 2018
e252103
Added test for sparse consolidation
TomAugspurger Jan 30, 2018
7110b2a
Docs
TomAugspurger Jan 30, 2018
c59dca0
Merge remote-tracking branch 'upstream/master' into pandas-array-inte…
TomAugspurger Jan 31, 2018
fc688a5
Moved to errors
TomAugspurger Jan 31, 2018
fbc8466
Handle classmethods, properties
TomAugspurger Jan 31, 2018
030bb19
Use our AbstractMethodError
TomAugspurger Jan 31, 2018
0f4c2d7
Lint
TomAugspurger Jan 31, 2018
f9316e0
Cleanup
TomAugspurger Feb 1, 2018
9c06b13
Move ndim validation to a method.
TomAugspurger Feb 1, 2018
7d2cf9c
Try this
TomAugspurger Feb 1, 2018
afae8ae
Make ExtensionBlock._holder a property
TomAugspurger Feb 1, 2018
cd0997e
Make _holder a property for all
TomAugspurger Feb 1, 2018
1d6eb04
Refactored validate_ndim
TomAugspurger Feb 1, 2018
92aed49
fixup! Refactored validate_ndim
TomAugspurger Feb 1, 2018
34134f2
lint
TomAugspurger Feb 1, 2018
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
Remove base
  • Loading branch information
TomAugspurger committed Jan 19, 2018
commit 57c749bd15a0ed28be1ad0c6012d2ba3fe650687
18 changes: 10 additions & 8 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ExtensionArray(object):

**Restrictions on your class constructor**

* Your class should be able to be constructed with instances of
our class, i.e. ``ExtensionArray(extension_array)`` should returns
an instance.
* Extension arrays should be able to be constructed with instances of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this formatting is a bit odd here

the class, i.e. ``ExtensionArray(extension_array)`` should return
an instance, not error.
"""
# ------------------------------------------------------------------------
# Must be a Sequence
Expand Down Expand Up @@ -69,10 +69,6 @@ def __len__(self):
# ------------------------------------------------------------------------
# Required attributes
# ------------------------------------------------------------------------
@property
def base(self):
"""The base array I am a view of. None by default."""

@property
@abc.abstractmethod
def dtype(self):
Expand All @@ -94,7 +90,11 @@ def ndim(self):
@abc.abstractmethod
def nbytes(self):
# type: () -> int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type comments come before the docstring: http://mypy.readthedocs.io/en/latest/python2.html

"""The number of bytes needed to store this object in memory."""
"""The number of bytes needed to store this object in memory.

If this is expensive to compute, return an approximate lower bound
on the number of bytes needed.
"""

# ------------------------------------------------------------------------
# Additional Methods
Expand Down Expand Up @@ -127,6 +127,8 @@ def take(self, indexer, allow_fill=True, fill_value=None):
Notes
-----
This should follow pandas' semantics where -1 indicates missing values.
Positions where indexer is ``-1`` should be filled with the missing
value for this type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's strongly consider exposing a helper function to make this easier to write, or at least an example of what this would look like (we can save this for later). It's not obvious how to write this with NumPy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example that I hope gets things correct for an extension type backed by a NumPy structured array.

One trouble with this providing a helper function is that we don't know much about how the extension array is actually storing the data. Although, we could rely on the assumption that the underlying storage is convertible to a NumPy array, and proceed from there. Though this would perhaps be sub-optimal for many extension arrays.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For GeometryArray, we have followed the same idea the write take (so it's not necessarily only if you have a structured array, just when you have an array backing up your ExtensionArray)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine as it is a pandas standard.


This is called by ``Series.__getitem__``, ``.loc``, ``iloc``, when the
indexer is a sequence of values.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def is_dtype(cls, dtype):
-----
The default implementation is True if

1. 'dtype' is a string that returns true for
``cls.construct_from_string``
1. ``cls.construct_from_string(dtype)`` is an instance
of ``cls``.
2. 'dtype' is ``cls`` or a subclass of ``cls``.
"""
if isinstance(dtype, str):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,

Returns
-------
IntervalArray
Block
"""
errors_legal_values = ('raise', 'ignore')

Expand Down