Skip to content

BUG: read_excel not working when filters are active and selected in worksheet #51557

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
2 of 3 tasks
KiaraShannen opened this issue Feb 22, 2023 · 6 comments
Closed
2 of 3 tasks
Labels
Closing Candidate May be closeable, needs more eyeballs IO Excel read_excel, to_excel Needs Info Clarification about behavior needed to assess issue Upstream issue Issue related to pandas dependency

Comments

@KiaraShannen
Copy link

KiaraShannen commented Feb 22, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

pd.read_excel("path to file")

Issue Description

Hi!
Since the update of openpyxl (31 january 2022) read_excel is no longer working properly to read excel files that have an active filter on them. With active filter i mean the filter function of excel where there is a selection active (for example one value in a column is excluded). Is there a method or way we can/argument to add in order to remove the auto filter from the file so that the file can be read again?

file from the pandas module where the error is found: site-packages/pandas/io/excel/_openpyxl.py
error: Value must be either numerical or a string containing a wildcard

current version of pandas: 1.5.3
Version in which it worked from openpyxl 3.0.10
No longer working in latest two versions of openpyxl

Thank you in advance!

Expected Behavior

Read the file without the active filters so that all data is included

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2e218d1 python : 3.9.5.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-1100-azure Version : #106~18.04.1-Ubuntu SMP Mon Dec 12 21:49:35 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
setuptools : 58.0.4
pip : 21.2.4
Cython : 0.29.24
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 2.11.3
IPython : 7.32.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.4.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.1
pandas_gbq : None
pyarrow : 7.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None

@KiaraShannen KiaraShannen added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 22, 2023
@phofl
Copy link
Member

phofl commented Feb 22, 2023

Hi, thanks for your report. Is this an intended feature from openpyxl? If no, you should probably open an issue there

@phofl phofl added IO Excel read_excel, to_excel Needs Info Clarification about behavior needed to assess issue and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 22, 2023
@KiaraShannen
Copy link
Author

Hi, thanks for your report. Is this an intended feature from openpyxl? If no, you should probably open an issue there

Hi!
Thank you for your quick response. Yes this was a conscious choice of openpyxl.
Beneath you'll find the edit logs in which they keep the autofilter on the file as default table filter.
In addition they do mention in their update that table filters are no longer overwritten.

https://foss.heptapod.net/openpyxl/openpyxl/-/commit/3af0b77f8a56820961e08e2e751026c984907a1d

@rhshadrach
Copy link
Member

rhshadrach commented Feb 23, 2023

I am not able to reproduce this, maybe I'm misunderstanding the issue. Here is my Excel file with row 3 filtered:

image

Then reading the file with openpyxl gives me all the data even though the filter is activated.

import openpyxl
print(openpyxl.__version__)
# 3.1.1
print(pd.read_excel('test.xlsx', engine='openpyxl'))
#    a  b  c
# 0  1  1  1
# 1  2  2  2
# 2  3  3  3

@KiaraShannen
Copy link
Author

KiaraShannen commented Feb 24, 2023

Okay as you were not able to reproduce i checked and it only occurs with files that have an active filter and some values of rows are empty

test file i created on which i get the error:
test_file_error.xlsx

@rhshadrach
Copy link
Member

Thanks for the example workbook. Running this, the ValueError I get is raised from site-packages/openpyxl/worksheet/filters.py. It appears to me this is an issue for openpyxl.

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs Upstream issue Issue related to pandas dependency labels Apr 13, 2023
@phofl
Copy link
Member

phofl commented Apr 22, 2023

Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs IO Excel read_excel, to_excel Needs Info Clarification about behavior needed to assess issue Upstream issue Issue related to pandas dependency
Projects
None yet
Development

No branches or pull requests

3 participants