Skip to content

Avoid import warning when lzma is missing #43461

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
rth opened this issue Sep 8, 2021 · 2 comments · Fixed by #43495
Closed

Avoid import warning when lzma is missing #43461

rth opened this issue Sep 8, 2021 · 2 comments · Fixed by #43495
Labels
Compat pandas objects compatability with Numpy or Python functions Warnings Warnings that appear or should be added to pandas
Milestone

Comments

@rth
Copy link
Contributor

rth commented Sep 8, 2021

Currently if Python is built without lzma, following #27882 a warning is going to be shown to users at import time,

lib/python3.9/site-packages/pandas/compat/__init__.py:117: UserWarning: Could not import the lzma
 module. Your installed Python is incomplete. Attempting to use lzma compression will result in a
 RuntimeError.

I don't believe this is helpful. While lzma is part of stdlib, CPython builds perfectly fine without lzma, and most of the test suite gracefully handles the fact that lzma might be missing.

Of course the RuntimeError is unavoidable, but I think the warning about "Your installed Python is incomplete" at import time is confusing to users. Particularly that in my, possibly biased experience, opening xz compressed files is not that common: users would most often either read plain text/csv for readability (possibly gzip compressed) or switch to parquet with compression if they care about size/performance. So most users should not be affected by this even if they don't have lzma.

For instance in Pyodide this warning makes users wonder what is wrong with their install pyodide/pyodide#1821 :) We will likely include lzma eventually, but so far there haven't been much requests for it (and every extra module has a download size penalty).

@TomAugspurger
Copy link
Contributor

Seeing that warning in pyodide made me wonder about revisiting this issue :) Thanks for opening this.

The fact that Python itself imports without warning when the lzma module isn't present is a pretty compelling argument to remove the warning. So I'd be +1 on removing it.

To avoid future regressions we would want to ensure that we have a test verifying that the lzma module isn't imported by default with pandas.

@lithomas1 lithomas1 added Compat pandas objects compatability with Numpy or Python functions Warnings Warnings that appear or should be added to pandas labels Sep 10, 2021
@lithomas1 lithomas1 added this to the Contributions Welcome milestone Sep 10, 2021
@rth
Copy link
Contributor Author

rth commented Sep 10, 2021

Thanks for the feedback, I'll open a PR.

@jreback jreback modified the milestones: Contributions Welcome, 1.4 Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants