-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Concat multiple different ExtensionArray types #22997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jorisvandenbossche
merged 9 commits into
pandas-dev:master
from
TomAugspurger:dtype-concat
Oct 18, 2018
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ed56aa3
API: ExtensionDtype Equality and Hashability
TomAugspurger 463c0bd
issue note
TomAugspurger 2a1660c
BUG: concat different EAs
TomAugspurger 48d7137
Merge remote-tracking branch 'upstream/master' into dtype-concat
TomAugspurger 869e2bf
Allow multiple fill values
TomAugspurger b6ccab4
skips
TomAugspurger 9507a0c
fixup [ci skip]
TomAugspurger 5502bb8
trigger CI
TomAugspurger e17d397
lint
TomAugspurger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,17 @@ class _DtypeOpsMixin(object): | |
# of the NA value, not the physical NA vaalue for storage. | ||
# e.g. for JSONArray, this is an empty dictionary. | ||
na_value = np.nan | ||
_metadata = () | ||
|
||
def __eq__(self, other): | ||
"""Check whether 'other' is equal to self. | ||
|
||
By default, 'other' is considered equal if | ||
By default, 'other' is considered equal if either | ||
|
||
* it's a string matching 'self.name'. | ||
* it's an instance of this type. | ||
* it's an instance of this type and all of the | ||
the attributes in ``self._metadata`` are equal between | ||
`self` and `other`. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -40,11 +43,19 @@ def __eq__(self, other): | |
bool | ||
""" | ||
if isinstance(other, compat.string_types): | ||
return other == self.name | ||
elif isinstance(other, type(self)): | ||
return True | ||
else: | ||
return False | ||
try: | ||
other = self.construct_from_string(other) | ||
except TypeError: | ||
return False | ||
if isinstance(other, type(self)): | ||
return all( | ||
getattr(self, attr) == getattr(other, attr) | ||
for attr in self._metadata | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corner case: other is an instance of a subclass of type(self) and self._metadata != other._metadata |
||
return False | ||
|
||
def __hash__(self): | ||
return hash(tuple(getattr(self, attr) for attr in self._metadata)) | ||
|
||
def __ne__(self, other): | ||
return not self.__eq__(other) | ||
|
@@ -161,6 +172,26 @@ class ExtensionDtype(_DtypeOpsMixin): | |
The `na_value` class attribute can be used to set the default NA value | ||
for this type. :attr:`numpy.nan` is used by default. | ||
|
||
ExtensionDtypes are required to be hashable. The base class provides | ||
a default implementation, which relies on the ``_metadata`` class | ||
attribute. ``_metadata`` should be a tuple containing the strings | ||
that define your data type. For example, with ``PeriodDtype`` that's | ||
the ``freq`` attribute. | ||
|
||
**If you have a parametrized dtype you should set the ``_metadata`` | ||
class property**. | ||
|
||
Ideally, the attributes in ``_metadata`` will match the | ||
parameters to your ``ExtensionDtype.__init__`` (if any). If any of | ||
the attributes in ``_metadata`` don't implement the standard | ||
``__eq__`` or ``__hash__``, the default implementations here will not | ||
work. | ||
|
||
.. versionchanged:: 0.24.0 | ||
|
||
Added ``_metadata``, ``__hash__``, and changed the default definition | ||
of ``__eq__``. | ||
|
||
This class does not inherit from 'abc.ABCMeta' for performance reasons. | ||
Methods and properties required by the interface raise | ||
``pandas.errors.AbstractMethodError`` and no ``register`` method is | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double back ticks