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

Suppressing XLRD warnings #16620

Closed
quertenmont opened this issue Jun 7, 2017 · 6 comments
Closed

Suppressing XLRD warnings #16620

quertenmont opened this issue Jun 7, 2017 · 6 comments
Labels
IO Excel read_excel, to_excel

Comments

@quertenmont
Copy link

Hello,

I would like to suppress some warnings from the xlrd module that appears when calling the pd.read_excel function

These are my typical warnings:
WARNING *** file size (608105) not 512 + multiple of sector size (512)
WARNING *** OLE2 inconsistency: SSCS size is 0 but SSAT size is non-zero

One of the solutions to this problem that I see on the web is to filter those via a log filter, see:
https://stackoverflow.com/questions/7619319/python-xlrd-suppress-warning-messages

But that would require having access to specify the logger in the read_excel function arguments.

Or is there another solution ?

Thanks,
Loic

@TomAugspurger
Copy link
Contributor

I think the proper solution is for xlrd to use the logging module. There's an issue here, if you want to resurrect it, or maybe submit a PR to xlrd.

In the meantime, does opening the workbook your self manually, and passing that to read_excel work for you?

Something like

import os
import pandas
import xlrd

wb = xlrd.open_workbook('file.xlsx', logfile=open(os.devnull, 'w'))
pd.read_excel(wb)

@TomAugspurger TomAugspurger added the IO Excel read_excel, to_excel label Jun 7, 2017
@quertenmont
Copy link
Author

It does the trick for me!
Thanks a lot for helping

@yoonghm
Copy link

yoonghm commented Dec 24, 2018

pd.read_excel(wb) could not read wb.

@ggodreau
Copy link

ggodreau commented Mar 5, 2019

Pls forgive the necrobumping here ☠️🤛

update for 2019:

import os
import pandas
import xlrd

wb = xlrd.open_workbook('file.xlsx', logfile=open(os.devnull, 'w'))
pd.read_excel(wb, engine='xlrd')

@tr0yspradling
Copy link

pd.read_excel(wb, engine='xlrd')
UnboundLocalError: local variable 'pd' referenced before assignment

Shouldn't this be pandas.read_excel(wb, engine='xlrd')?

@yoonghm
Copy link

yoonghm commented Jun 1, 2019

The solution provided above redirects standard error outputs to null device,

import os
import pandas as pd
import xlrd

wb = xlrd.open_workbook('file.xlsx', logfile=open(os.devnull, 'w'))
pd.read_excel(wb, engine='xlrd')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

5 participants