Description
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
Issue Description
On some Python installations, the libbzip2 headers are not compiled into Python. This is also true on some lightweight Python binaries, including (recently) several used by GitHub actions. It does not make much sense for pandas to require bz2
if one is not doing bzip compression, so I think this import should be safely skipped if not available.
You can see several of the GitHub actions for PySR are now failing due to a pandas import: https://github.com/MilesCranmer/PySR/actions/runs/5376798563, despite bzip2 compression never being used in the unittests.
Using /Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages
Finished processing dependencies for pysr==0.14.2
Traceback (most recent call last):
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/Users/runner/work/PySR/PySR/pysr/__init__.py", line 3, in <module>
from .sr import (
File "/Users/runner/work/PySR/PySR/pysr/sr.py", line 7, in <module>
import pandas as pd
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/__init__.py", line 50, in <module>
from pandas.core.api import (
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/core/api.py", line 48, in <module>
from pandas.core.groupby import (
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
from pandas.core.groupby.generic import (
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 73, in <module>
from pandas.core.frame import DataFrame
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/core/frame.py", line 129, in <module>
from pandas.core import (
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/core/generic.py", line 122, in <module>
from pandas.core.describe import describe_ndframe
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/core/describe.py", line 39, in <module>
from pandas.io.formats.format import format_percentiles
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/io/formats/format.py", line 99, in <module>
from pandas.io.common import stringify_path
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pandas/io/common.py", line 4, in <module>
import bz2
File "/Users/runner/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/bz2.py", line 19, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
Error: Process completed with exit code 1.
I will submit a PR to fix this shortly.
Expected Behavior
N/A
Installed Versions
N/A