-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Naming inconsistency in import of maybe_convert_indices in pandas.core.index.py #10610
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
Comments
I think code is unreachable actually. Want to put a halt there and see if its every hit in the test suite? if not can manufacture a test to see what gets's u there and fix. |
I got to that location by passing an array of integers and a list of integers as a column index. |
oh ok sounds like we need s test case and fix then! |
can you post the example which hits this code? |
>>> import pandas as pd
>>> import numpy as np
>>> d = pd.DataFrame(np.random.random((10, 5)), columns=["a"] + np.arange(20,24).tolist())
>>> print(d[[23,26]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/djgagne/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 1791, in __getitem__
return self._getitem_array(key)
File "/Users/djgagne/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 1835, in _getitem_array
indexer = self.ix._convert_to_indexer(key, axis=1)
File "/Users/djgagne/anaconda/lib/python2.7/site-packages/pandas/core/indexing.py", line 1082, in _convert_to_indexer
indexer = labels._convert_list_indexer(objarr, kind=self.name)
File "/Users/djgagne/anaconda/lib/python2.7/site-packages/pandas/core/index.py", line 930, in _convert_list_indexer
from pandas.core.indexing import _maybe_convert_indices
ImportError: cannot import name _maybe_convert_indices To trigger this section of code, one has to create a DataFrame with a column index that contains a mix of strings and integers as the labels. Then when accessing the columns, one has to pass a list of integers that contain at least one value outside the range of indices or values. Then the code is hit. It is admittedly a rare path to take, and having mixed integers and strings as column labels is probably not the best idea, but it can be done. A KeyError should at least be thrown for 26, which does happen when the column labels are all integers. |
i c. ok, want to add that as a test and see if it fixes (the import fix). |
Just hit this error today. For anyone who gets here via google and is newer to Python - you can fix this in your code by just updating your column index to contain only strings. You can print your columns, then copy/paste and update whichever need to be changed print df.columns |
@djgagne @christopher-llop want to do a pull-request to fix? |
I should be able to make a pull-request to fix the problem in the next week. |
@djgagne or @christopher-llop pull-request? |
I submitted a pull request here: #10872 |
…o raise IndexError.
closed by #10872 |
In lines 930-931 of pandas.core.index.py, the following code states
In pandas.core.indexing.py, the function is called
maybe_convert_indices
. In the 3 other places where the function is called, it is called using the correct name. The leading underscore should be removed from the function name in index.py.The text was updated successfully, but these errors were encountered: