Skip to content
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

Allow IntervalIndex.astype to change subtypes when passed an IntervalDtype #19197

Closed
jschendel opened this Issue Jan 12, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@jschendel
Copy link
Member

jschendel commented Jan 12, 2018

Problem description

Currently IntervalIndex.astype doesn't do anything when passed an IntervalDtype:

In [2]: ii = pd.interval_range(0.0, 3.0)

In [3]: ii
Out[3]:
IntervalIndex([(0.0, 1.0], (1.0, 2.0], (2.0, 3.0]]
              closed='right',
              dtype='interval[float64]')

In [4]: dtype = IntervalDtype('int64')

In [5]: ii.astype(dtype)
Out[5]:
IntervalIndex([(0.0, 1.0], (1.0, 2.0], (2.0, 3.0]]
              closed='right',
              dtype='interval[float64]')

This is because the current implementation of IntervalIndex.astype doesn't distinguish between different IntervalDtype, and treats them all as equivalent to the existing dtype:

def astype(self, dtype, copy=True):
if is_interval_dtype(dtype):
return self.copy() if copy else self

Expected Output

I'd expect the subtype to be converted to 'int64':

Out[5]:
IntervalIndex([(0, 1], (1, 2], (2, 3]]
              closed='right',
              dtype='interval[int64]')

@jreback jreback added this to the Next Major Release milestone Jan 13, 2018

@jreback jreback modified the milestones: Next Major Release, 0.23.0 Jan 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.