err#8038: Index.shift() gives confusing error message when no Datetim… by hamedhsn · Pull Request #11211 · pandas-dev/pandas (original) (raw)
@jreback @hamedhsn I think this behavior is confusing. I think there are some reasons to shift a non-DateTime-like index, but it shouldn't be done with a freq.
Do you guys think this is clear and expected behavior?
idx = Index(range(5))
result = idx.shift(periods=2, freq=2)
expected = pd.Index(range(4, 9))
self.assert_index_equal(result, expected)A version I could see being helpful is to shift by a number of items. i.e. this:
idx = Index(range(5,10))
result = idx.shift(1)
expected = pd.Index(range(6, 11))
self.assert_index_equal(result, expected)...although I'm more against the current implementation than I am fighting for this specific implementation.
As ever, open to being wrong though.