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

read_excel(..., index_col=0, squeeze=True) raises AttributeError #12157

Closed
rafguns opened this issue Jan 27, 2016 · 1 comment
Closed

read_excel(..., index_col=0, squeeze=True) raises AttributeError #12157

rafguns opened this issue Jan 27, 2016 · 1 comment
Labels
Bug IO Excel read_excel, to_excel Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@rafguns
Copy link

rafguns commented Jan 27, 2016

pd.read_excel with keyword argument squeeze=True raises an AttributeError. This is unexpected, in that:

  • I would expect it to work analogously to pd.read_csv, which does not exhibit the same problem
  • it worked fine in a previous version (0.15 I think?)

Steps to reproduce:

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '0.17.1'

In [3]: df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

In [4]: df.to_csv('tmp.csv', index=False)

In [5]: df.to_excel('tmp.xlsx', index=False)

In [6]: pd.read_csv('tmp.csv', index_col=0, squeeze=True)
Out[6]:
a
1    3
2    4
Name: b, dtype: int64

In [7]: pd.read_excel('tmp.xlsx', index_col=0, squeeze=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-ed256b323894> in <module>()
----> 1 pd.read_excel('tmp.xlsx', index_col=0, squeeze=True)

C:\Anaconda3\lib\site-packages\pandas\io\excel.py in read_excel(io, sheetname, header, skiprows, skip_footer, index_col, parse_cols, parse_dates, date_parser, na_values, thousands, convert_float, has_index_names, converters, engine, **kwds)
    168         date_parser=date_parser, na_values=na_values, thousands=thousands,
    169         convert_float=convert_float, has_index_names=has_index_names,
--> 170         skip_footer=skip_footer, converters=converters, **kwds)
    171
    172 class ExcelFile(object):

C:\Anaconda3\lib\site-packages\pandas\io\excel.py in _parse_excel(self, sheetname, header, skiprows, skip_footer, index_col, has_index_names, parse_cols, parse_dates, date_parser, na_values, thousands, convert_float, verbose, **kwds)
    437
    438             output[asheetname] = parser.read()
--> 439             output[asheetname].columns = output[asheetname].columns.set_names(header_names)
    440
    441         if ret_dict:

C:\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   2353                 or name in self._metadata
   2354                 or name in self._accessors):
-> 2355             return object.__getattribute__(self, name)
   2356         else:
   2357             if name in self._info_axis:

AttributeError: 'Series' object has no attribute 'columns'
@chris-b1
Copy link
Contributor

I was the culprit here - #10967, looks like squeeze is untested on read_excel. Probably just need a little extra logic around that name assignment, I can take a look.

@jreback jreback added Bug Regression Functionality that used to work in a prior pandas version IO Excel read_excel, to_excel labels Jan 27, 2016
@jreback jreback added this to the Next Major Release milestone Jan 27, 2016
@jreback jreback modified the milestones: 0.18.0, Next Major Release Jan 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Excel read_excel, to_excel Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants