-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: lzma is a required part of python, make it optional #27882
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
BUG: lzma is a required part of python, make it optional #27882
Conversation
raise a warning. Substituted import lzma for helper function.
I cannot modify the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @salompas.
We'll also want
- A release note in 0.25.1.rst. Can go under the "IO" bug fixes section.
- Update the uses of lzma to raise a RuntimeError when a broken Python install tries to use lzma
- A test
For the test, something like
diff --git a/pandas/tests/io/test_compression.py b/pandas/tests/io/test_compression.py
index ce459ab24..0d359dd72 100644
--- a/pandas/tests/io/test_compression.py
+++ b/pandas/tests/io/test_compression.py
@@ -1,5 +1,7 @@
import contextlib
import os
+import subprocess
+import textwrap
import warnings
import pytest
@@ -125,3 +127,15 @@ def test_compression_warning(compression_only):
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False):
with f:
df.to_csv(f, compression=compression_only)
+
+
+def test_with_missing_lzma():
+ # https://github.com/pandas-dev/pandas/issues/27575
+ code = textwrap.dedent(
+ """\
+ import sys
+ sys.modules['lzma'] = None
+ import pandas
+ """
+ )
+ subprocess.check_output(["python", "-c", code])
What issues do you see? You'll need a C compiler, since you're updating a Cython file. Typically I use |
I was adding an
I am modifying the file in Emacs without any mode for Cython. |
I managed to make it work in |
This is much smarter than what I was doing to test the code (change the name of the |
you try importing it.
I do not understand what the command |
Please let me know if this is looking good, and how I can improve the solution. |
…ma-compression-optional
That means it is passing that check. The isort check is failing. Should be fixed if you run |
I made the changes you suggested, let me know how it is looking now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty close. Can you
- Rename
import_lzma
to_import_lzma
(pandas.compat
is supposed to be private, but people still use it) - move the
if lzma is None
check to a new method inpandas/compat/__init__.py
called_get_lzma_file(lzma)
. Iflzma
is None it raises the RuntimeError. Otherwise, it returnslzma.LZMAFile
, which we can pass the kwargs to when lzma is not None. - Add at least one subprocess-style test that hits the RuntimeError.
RuntimeError if the check fails. Updated remainder of the code to use this function.
succeeds if lzma module is available.
Done. |
Just for my future reference.
When saving a file, the function |
I guess another modification to this code is to show the warning just once (right now it shows up twice), but this might not be worth the time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a double warning is fine. Don't worry about that.
One request for changes on the second test. Otherwise, this looks great.
import lzma
can fail #27575
@jreback @TomAugspurger |
Thanks @salompas! |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
… make it optional
Backported in #28012. |
…27882) * Importing lzma when Python has been compiled without its support will raise a warning. Substituted import lzma for helper function.
…27882) * Importing lzma when Python has been compiled without its support will raise a warning. Substituted import lzma for helper function.
I opened #43461 to re-visit this. I would like to propose to remove the import warning if lzma is missing. Please comment in the linked issue if you disagree. |
Importing
lzma
when Python has been compiled without its support (usually due to a lack ofxz
in the system) will raise a warning. Substitutedimport lzma
for helper function.black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff