Skip to content

Avoid import warning when lzma is missing #43461

Closed
@rth

Description

@rth

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsWarningsWarnings that appear or should be added to pandas

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions