Skip to content

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

Closed
djgagne opened this issue Jul 17, 2015 · 13 comments
Closed
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@djgagne
Copy link

djgagne commented Jul 17, 2015

In lines 930-931 of pandas.core.index.py, the following code states

from pandas.core.indexing import _maybe_convert_indices
return _maybe_convert_indices(indexer, len(self))

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.

@jreback
Copy link
Contributor

jreback commented Jul 17, 2015

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.

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Jul 17, 2015
@djgagne
Copy link
Author

djgagne commented Jul 17, 2015

I got to that location by passing an array of integers and a list of integers as a column index.

@jreback
Copy link
Contributor

jreback commented Jul 17, 2015

oh ok

sounds like we need s test case and fix then!

@jreback
Copy link
Contributor

jreback commented Jul 17, 2015

can you post the example which hits this code?

@djgagne
Copy link
Author

djgagne commented Jul 17, 2015

>>> 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.

@jreback
Copy link
Contributor

jreback commented Jul 17, 2015

i c. ok, want to add that as a test and see if it fixes (the import fix).

@jreback jreback added this to the 0.17.0 milestone Jul 17, 2015
@christopher-llop
Copy link

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
df.columns = ['1', '2', '3', 'A', 'B', 'C']

@jreback
Copy link
Contributor

jreback commented Aug 13, 2015

@djgagne @christopher-llop want to do a pull-request to fix?

@christopher-llop
Copy link

@jreback would love to but dealing with finals. If this is still an issue in a couple weeks I'll circle back - been looking for a project for the week between semesters. @djgagne if you have time, by all means go ahead

@djgagne
Copy link
Author

djgagne commented Aug 13, 2015

I should be able to make a pull-request to fix the problem in the next week.

@jreback
Copy link
Contributor

jreback commented Aug 20, 2015

@djgagne or @christopher-llop pull-request?

@djgagne
Copy link
Author

djgagne commented Aug 20, 2015

I submitted a pull request here: #10872

@jreback
Copy link
Contributor

jreback commented Sep 1, 2015

closed by #10872

@jreback jreback closed this as completed Sep 1, 2015
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 a pull request may close this issue.

3 participants