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

BUG: Revisit Index.delete preserves freq #7320

Merged
merged 1 commit into from
Jun 5, 2014
Merged

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Jun 3, 2014

Fix the issue that freq is preserved inappropriately, caused by #7302. Fix preserves freq if edge element is being deleted (same as #7299).
CC: @rosnfeld

@jreback jreback added this to the 0.14.1 milestone Jun 3, 2014
@jreback
Copy link
Contributor

jreback commented Jun 3, 2014

ok looks good thanks

@rosnfeld
Copy link
Contributor

rosnfeld commented Jun 3, 2014

I tried the same exercise as before, and it didn't work for me:

In [1]: ts = pd.Series(1, 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
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-3de5d002e589> in <module>()
----> 1 ts.drop(ts.index[[5,6,7]]).index

/home/andrew/git/pandas-rosnfeld/pandas/core/generic.py in drop(self, labels, axis, level, inplace, **kwargs)
   1462                 new_axis = axis.drop(labels, level=level)
   1463             else:
-> 1464                 new_axis = axis.drop(labels)
   1465             dropped = self.reindex(**{axis_name: new_axis})
   1466             try:

/home/andrew/git/pandas-rosnfeld/pandas/core/index.py in drop(self, labels)
   1801         if mask.any():
   1802             raise ValueError('labels %s not contained in axis' % labels[mask])
-> 1803         return self.delete(indexer)
   1804 
   1805 

/home/andrew/git/pandas-rosnfeld/pandas/tseries/index.py in delete(self, loc)
   1618         """
   1619         new_dates = np.delete(self.asi8, loc)
-> 1620         if loc in (0, -len(self), -1, len(self) - 1):
   1621             freq = self.freq
   1622         else:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

@sinhrks
Copy link
Member Author

sinhrks commented Jun 3, 2014

Thanks for your confirmation. I didn't imagine loc can be list or array.. I'll reconsider the logic.

@jreback
Copy link
Contributor

jreback commented Jun 3, 2014

@sinhrks is this updated with @rosnfeld example?

@sinhrks
Copy link
Member Author

sinhrks commented Jun 5, 2014

@jreback @rosnfeld Updated to accept int, slice and np.array as the same as np.delete, and added test cases for these.

@jreback
Copy link
Contributor

jreback commented Jun 5, 2014

@rosnfeld can you give this a try?

@rosnfeld
Copy link
Contributor

rosnfeld commented Jun 5, 2014

Looks good.

jreback added a commit that referenced this pull request Jun 5, 2014
BUG: Revisit Index.delete preserves freq
@jreback jreback merged commit 4296c3a into pandas-dev:master Jun 5, 2014
@jreback
Copy link
Contributor

jreback commented Jun 5, 2014

thanks @sinhrks !

@sinhrks sinhrks deleted the delete branch June 6, 2014 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants