Skip to content

BUG: df.shift(axis=1) complains about index out of range #7978

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

Closed
alan-wong opened this issue Aug 10, 2014 · 3 comments
Closed

BUG: df.shift(axis=1) complains about index out of range #7978

alan-wong opened this issue Aug 10, 2014 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request

Comments

@alan-wong
Copy link

I just tried to pass axis=1 on a shift call to a dataframe and it threw an error, I couldn't find an issue here and this is the first time I tried this function so not sure if this was something that used to work and then got broken.

I'm using python 64-bit 3.3.4, pandas 0.14.1 and numpy 1.8.1

In [57]:

df = pd.DataFrame({'a':randn(10), 'b':randn(10)})
df.shift(axis=1)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-57-160107eee7e4> in <module>()
      1 df = pd.DataFrame({'a':randn(10), 'b':randn(10)})
----> 2 df.shift(axis=1)

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\generic.py in shift(self, periods, freq, axis, **kwds)
   3173             block_axis = self._get_block_manager_axis(axis)
   3174             indexer = com._shift_indexer(len(self), periods)
-> 3175             new_data = self._data.shift(indexer, periods, axis=block_axis)
   3176         else:
   3177             return self.tshift(periods, freq, **kwds)

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\internals.py in shift(self, *args, **kwargs)
   2405 
   2406     def shift(self, *args, **kwargs):
-> 2407         return self.apply('shift', *args, **kwargs)
   2408 
   2409     def fillna(self, *args, **kwargs):

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\internals.py in apply(self, f, *args, **kwargs)
   2373 
   2374             else:
-> 2375                 applied = getattr(blk, f)(*args, **kwargs)
   2376 
   2377             if isinstance(applied, list):

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\internals.py in shift(self, indexer, periods, axis)
    916         """ shift the block by periods, possibly upcast """
    917 
--> 918         new_values = self.values.take(indexer, axis=axis)
    919         # convert integer to float if necessary. need to do a lot more than
    920         # that, handle boolean etc also

IndexError: index 2 is out of bounds for size 2
In [57]:

df = pd.DataFrame({'a':randn(10), 'b':randn(10)})
df.shift(axis=1)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-57-160107eee7e4> in <module>()
      1 df = pd.DataFrame({'a':randn(10), 'b':randn(10)})
----> 2 df.shift(axis=1)

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\generic.py in shift(self, periods, freq, axis, **kwds)
   3173             block_axis = self._get_block_manager_axis(axis)
   3174             indexer = com._shift_indexer(len(self), periods)
-> 3175             new_data = self._data.shift(indexer, periods, axis=block_axis)
   3176         else:
   3177             return self.tshift(periods, freq, **kwds)

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\internals.py in shift(self, *args, **kwargs)
   2405 
   2406     def shift(self, *args, **kwargs):
-> 2407         return self.apply('shift', *args, **kwargs)
   2408 
   2409     def fillna(self, *args, **kwargs):

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\internals.py in apply(self, f, *args, **kwargs)
   2373 
   2374             else:
-> 2375                 applied = getattr(blk, f)(*args, **kwargs)
   2376 
   2377             if isinstance(applied, list):

C:\WinPython-64bit-3.3.5.0\python-3.3.5.amd64\lib\site-packages\pandas\core\internals.py in shift(self, indexer, periods, axis)
    916         """ shift the block by periods, possibly upcast """
    917 
--> 918         new_values = self.values.take(indexer, axis=axis)
    919         # convert integer to float if necessary. need to do a lot more than
    920         # that, handle boolean etc also

IndexError: index 2 is out of bounds for size 2
@alan-wong alan-wong changed the title df.shift(axis=1) complains about index out of range BUG: df.shift(axis=1) complains about index out of range Aug 10, 2014
@jreback
Copy link
Contributor

jreback commented Aug 10, 2014

this works in 0.14.1 (on 3.3,numpy 1.8, on windows). Looking at the code that you are showing in the error, that looks like some prior code (this was changed in 0.14.0), see #6672. Pls verify that you are actually importing 0.14.1.

@alan-wong
Copy link
Author

Argh.. so sorry Jeff, I'm actually running 0.13.1, I thought my laptop was running the same version as my desktop which is running 0.14.1. My apologies, thanks for the quick response, how do I close this?

@jreback
Copy link
Contributor

jreback commented Aug 10, 2014

@alan-wong np...always appreciate the reports

@jreback jreback closed this as completed Aug 10, 2014
@jreback jreback added the Dupe label Aug 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants