Skip to content

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

Merged
merged 20 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c1a5326
Importing lzma when Python has been compiled without its support will
guilherme-salome Aug 12, 2019
f9b420b
Substituted import lzma to call to import_lzma
guilherme-salome Aug 12, 2019
998b5aa
Calls to lzma module will raise a RuntimeError.
guilherme-salome Aug 12, 2019
6c53d80
Formatted with black.
guilherme-salome Aug 12, 2019
2415e1f
Raise RuntimeError when calling a method of lzma when lzma is not ava…
guilherme-salome Aug 12, 2019
52cb8ed
Release not explaining solution to #27575.
guilherme-salome Aug 12, 2019
3401cd5
Moved import warnings to top.
guilherme-salome Aug 12, 2019
10fecae
Added test for import lzma. Test passes when lzma is not available and
guilherme-salome Aug 12, 2019
c79e31b
Improved explanation of solution to #27575.
guilherme-salome Aug 12, 2019
f22bf4f
Merge branch 'master' of https://github.com/pandas-dev/pandas into lz…
guilherme-salome Aug 12, 2019
68de9de
Fixed isort.
guilherme-salome Aug 13, 2019
7656b34
Removed remains from a merge.
guilherme-salome Aug 13, 2019
e74dc30
Moved I/O and LZMA bug fix to a separate section.
guilherme-salome Aug 13, 2019
881fc12
Unecessary import.
guilherme-salome Aug 13, 2019
2e4e422
Updated RuntimeError message to alert user that a re-install might be…
guilherme-salome Aug 13, 2019
351d8e4
Moved the check `lzma is None` to a function, which also raises
guilherme-salome Aug 13, 2019
ea0fd69
Removed bulletpoints.
guilherme-salome Aug 13, 2019
d65110d
Added test that fails at Runtime when lzma module not available. Test
guilherme-salome Aug 13, 2019
18405a6
Modified runtime test to make direct call to pandas function.
guilherme-salome Aug 15, 2019
af64991
Added docstring.
guilherme-salome Aug 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# See LICENSE for the license
import bz2
import gzip
import lzma
import os
import sys
import time
Expand Down Expand Up @@ -59,9 +58,12 @@ from pandas.core.arrays import Categorical
from pandas.core.dtypes.concat import union_categoricals
import pandas.io.common as icom

from pandas.compat import import_lzma
from pandas.errors import (ParserError, DtypeWarning,
EmptyDataError, ParserWarning)

lzma = import_lzma()

# Import CParserError as alias of ParserError for backwards compatibility.
# Ultimately, we want to remove this import. See gh-12665 and gh-14479.
CParserError = ParserError
Expand Down
13 changes: 13 additions & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ def is_platform_mac():

def is_platform_32bit():
return struct.calcsize("P") * 8 < 64


def import_lzma():
import warnings
try:
import lzma
return lzma
except ImportError:
msg = (
"Could not import the lzma module. Your installed Python is incomplete. "
"Attempting to use `lzma` compression will result in a RuntimeError."
)
warnings.warn(msg)
4 changes: 3 additions & 1 deletion pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import gzip
from http.client import HTTPException # noqa
from io import BytesIO
import lzma
import mmap
import os
import pathlib
Expand All @@ -31,10 +30,13 @@
ParserWarning,
)

from pandas.compat import import_lzma
from pandas.core.dtypes.common import is_file_like

from pandas._typing import FilePathOrBuffer

lzma = import_lzma()

# gh-12665: Alias for now and remove later.
CParserError = ParserError

Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import bz2
import glob
import gzip
import lzma
import os
import pickle
import shutil
Expand All @@ -22,14 +21,16 @@

import pytest

from pandas.compat import is_platform_little_endian
from pandas.compat import is_platform_little_endian, import_lzma

import pandas as pd
from pandas import Index
import pandas.util.testing as tm

from pandas.tseries.offsets import Day, MonthEnd

lzma = import_lzma()


@pytest.fixture(scope="module")
def current_pickle_data():
Expand Down
7 changes: 4 additions & 3 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from functools import wraps
import gzip
import http.client
import lzma
import os
import re
from shutil import rmtree
Expand All @@ -26,7 +25,7 @@
)

import pandas._libs.testing as _testing
from pandas.compat import raise_with_traceback
from pandas.compat import raise_with_traceback, import_lzma

from pandas.core.dtypes.common import (
is_bool,
Expand Down Expand Up @@ -70,6 +69,8 @@
from pandas.io.common import urlopen
from pandas.io.formats.printing import pprint_thing

lzma = import_lzma()

N = 30
K = 4
_RAISE_NETWORK_ERROR_DEFAULT = False
Expand Down Expand Up @@ -264,7 +265,7 @@ def write_to_compressed(compression, path, data, dest="test"):

compress_method = bz2.BZ2File
elif compression == "xz":
import lzma
lzma = import_lzma()

compress_method = lzma.LZMAFile
else:
Expand Down