Skip to content

REF: share IntervalIndex.intersection with Index.intersection #38373

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
merged 3 commits into from
Dec 12, 2020

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Dec 8, 2020

This changes the return dtype of IntervalIndex.intersection when that intersection is empty.

@jbrockmendel jbrockmendel mentioned this pull request Dec 9, 2020
5 tasks
@jreback jreback added Index Related to the Index class or subclasses Refactor Internal refactoring of code labels Dec 12, 2020
@jreback jreback added this to the 1.3 milestone Dec 12, 2020
@jreback jreback merged commit 3999efa into pandas-dev:master Dec 12, 2020
@jreback
Copy link
Contributor

jreback commented Dec 12, 2020

nice!

@jbrockmendel jbrockmendel deleted the ref-setops-48 branch December 13, 2020 00:01
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Can you also add tests for concat with interval dtypes? (that will also be affected by this change)

def _get_common_dtype(self, dtypes: List[DtypeObj]) -> Optional[DtypeObj]:
# NB: this doesn't handle checking for closed match
if not all(isinstance(x, IntervalDtype) for x in dtypes):
return np.dtype(object)
Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong return value, see docstring in the base class:

def _get_common_dtype(self, dtypes: List[DtypeObj]) -> Optional[DtypeObj]:
"""
Return the common dtype, if one exists.
Used in `find_common_type` implementation. This is for example used
to determine the resulting dtype in a concat operation.
If no common dtype exists, return None (which gives the other dtypes
the chance to determine a common dtype). If all dtypes in the list
return None, then the common dtype will be "object" dtype (this means
it is never needed to return "object" dtype from this method itself).
Parameters
----------
dtypes : list of dtypes
The dtypes for which to determine a common dtype. This is a list
of np.dtype or ExtensionDtype instances.
Returns
-------
Common dtype (np.dtype or ExtensionDtype) or None

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, will address in follow-up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: find_common_type([interval[f8], interval[i8]]) returns object
3 participants