|
5 | 5 | from functools import wraps
|
6 | 6 | import gzip
|
7 | 7 | import http.client
|
8 |
| -import lzma |
9 | 8 | import os
|
10 | 9 | import re
|
11 | 10 | from shutil import rmtree
|
|
26 | 25 | )
|
27 | 26 |
|
28 | 27 | import pandas._libs.testing as _testing
|
29 |
| -from pandas.compat import raise_with_traceback |
| 28 | +from pandas.compat import _get_lzma_file, _import_lzma, raise_with_traceback |
30 | 29 |
|
31 | 30 | from pandas.core.dtypes.common import (
|
32 | 31 | is_bool,
|
|
70 | 69 | from pandas.io.common import urlopen
|
71 | 70 | from pandas.io.formats.printing import pprint_thing
|
72 | 71 |
|
| 72 | +lzma = _import_lzma() |
| 73 | + |
73 | 74 | N = 30
|
74 | 75 | K = 4
|
75 | 76 | _RAISE_NETWORK_ERROR_DEFAULT = False
|
@@ -211,7 +212,7 @@ def decompress_file(path, compression):
|
211 | 212 | elif compression == "bz2":
|
212 | 213 | f = bz2.BZ2File(path, "rb")
|
213 | 214 | elif compression == "xz":
|
214 |
| - f = lzma.LZMAFile(path, "rb") |
| 215 | + f = _get_lzma_file(lzma)(path, "rb") |
215 | 216 | elif compression == "zip":
|
216 | 217 | zip_file = zipfile.ZipFile(path)
|
217 | 218 | zip_names = zip_file.namelist()
|
@@ -264,9 +265,7 @@ def write_to_compressed(compression, path, data, dest="test"):
|
264 | 265 |
|
265 | 266 | compress_method = bz2.BZ2File
|
266 | 267 | elif compression == "xz":
|
267 |
| - import lzma |
268 |
| - |
269 |
| - compress_method = lzma.LZMAFile |
| 268 | + compress_method = _get_lzma_file(lzma) |
270 | 269 | else:
|
271 | 270 | msg = "Unrecognized compression type: {}".format(compression)
|
272 | 271 | raise ValueError(msg)
|
|
0 commit comments