BUG: AttributeError raised when reading from excel file containing chart sheet · Issue #41448 · pandas-dev/pandas (original) (raw)

When reading an excel file that contains a chart sheet (a sheet that contains a chart and no table), the following exception was raised:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-89c95e3cb7b1> in <module>
      1 import pandas
----> 2 pandas.read_excel('chartsheet.xlsx', sheet_name=None)

D:\Softwares\Anaconda\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    297                 )
    298                 warnings.warn(msg, FutureWarning, stacklevel=stacklevel)
--> 299             return func(*args, **kwargs)
    300 
    301         return wrapper

D:\Softwares\Anaconda\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
    365             skipfooter=skipfooter,
    366             convert_float=convert_float,
--> 367             mangle_dupe_cols=mangle_dupe_cols,
    368         )
    369     finally:

D:\Softwares\Anaconda\lib\site-packages\pandas\io\excel\_base.py in parse(self, sheet_name, header, names, index_col, usecols, squeeze, converters, true_values, false_values, skiprows, nrows, na_values, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, **kwds)
   1188             convert_float=convert_float,
   1189             mangle_dupe_cols=mangle_dupe_cols,
-> 1190             **kwds,
   1191         )
   1192 

D:\Softwares\Anaconda\lib\site-packages\pandas\io\excel\_base.py in parse(self, sheet_name, header, names, index_col, usecols, squeeze, dtype, true_values, false_values, skiprows, nrows, na_values, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, **kwds)
    490                 sheet = self.get_sheet_by_index(asheetname)
    491 
--> 492             data = self.get_sheet_data(sheet, convert_float)
    493             usecols = maybe_convert_usecols(usecols)
    494 

D:\Softwares\Anaconda\lib\site-packages\pandas\io\excel\_openpyxl.py in get_sheet_data(self, sheet, convert_float)
    546         data: List[List[Scalar]] = []
    547         last_row_with_data = -1
--> 548         for row_number, row in enumerate(sheet.rows):
    549             converted_row = [self._convert_cell(cell, convert_float) for cell in row]
    550             if not all(cell == "" for cell in converted_row):

AttributeError: 'Chartsheet' object has no attribute 'rows'

I expect that either the chart sheet is ignored, returned as some appropriate object, or a warning is shown that the chart sheet cannot be read, instead of raising the exception.

In my case I'm reading from many zipped archives of excel files, so manually removing the charts from the files is not an option.