Skip to content

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented May 31, 2014

Made Index.delete to preserve name, tz and freq attributes.

@jreback jreback added this to the 0.14.1 milestone Jun 1, 2014
jreback added a commit that referenced this pull request Jun 1, 2014
BUG: Index.delete doesnt preserve name and other attrs
@jreback jreback merged commit 069f144 into pandas-dev:master Jun 1, 2014
@jreback
Copy link
Contributor

jreback commented Jun 1, 2014

thanks

@rosnfeld
Copy link
Contributor

rosnfeld commented Jun 2, 2014

Ok, putting this comment in the right place now (was on #7299):

I just pulled this change in and it threw me for a loop until I figured out what was going on (and hopefully I understand it correctly). I was working on fixing some plotting bugs like #2960 and this actually changes the behavior of the setup case provided in that issue. It used to be that dropping items from a regular timeseries would make that timeseries "irregular" (by dropping the freq), making it plot differently, etc.

I'm fine with this new behavior but was the old behavior there for a reason? I had gotten used to it.

@jreback
Copy link
Contributor

jreback commented Jun 2, 2014

have to revisit this (in 7299)

because adding/deleting a stamp can change the freq (eg make it none); though it could also not change it if say deleting from the end

I think the behavior was to always make it reinfer - so not sure it should actually different

do u have an example?

@rosnfeld
Copy link
Contributor

rosnfeld commented Jun 3, 2014

Sure, here's an example. The last case (inspired by #2960) differs. Maybe that's fine?

(I thought it might be more far-reaching but apparently not.)

On master:

In [14]: ts = pd.Series(index=pd.date_range('2000-01-01', periods=10, freq='D'))

In [15]: ts[:5].index
Out[15]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01, ..., 2000-01-05]
Length: 5, Freq: D, Timezone: None

In [16]: ts[[1,2,3]].index
Out[16]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-02, ..., 2000-01-04]
Length: 3, Freq: None, Timezone: None

In [17]: ts.drop(ts.index[[5,6,7]]).index
Out[17]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01, ..., 2000-01-10]
Length: 7, Freq: D, Timezone: None

On 0.14.0:

In [1]: ts = pd.Series(index=pd.date_range('2000-01-01', periods=10, freq='D'))

In [2]: ts[:5].index
Out[2]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01, ..., 2000-01-05]
Length: 5, Freq: D, Timezone: None

In [3]: ts[[1,2,3]].index
Out[3]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-02, ..., 2000-01-04]
Length: 3, Freq: None, Timezone: None

In [4]: ts.drop(ts.index[[5,6,7]]).index
Out[4]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2000-01-01, ..., 2000-01-10]
Length: 7, Freq: None, Timezone: None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants