|
10 | 10 | from shutil import rmtree
|
11 | 11 | import string
|
12 | 12 | import tempfile
|
13 |
| -from typing import Any, Callable, ContextManager, List, Optional, Type, Union, cast |
| 13 | +from typing import ( |
| 14 | + Any, |
| 15 | + Callable, |
| 16 | + ContextManager, |
| 17 | + List, |
| 18 | + Optional, |
| 19 | + Tuple, |
| 20 | + Type, |
| 21 | + Union, |
| 22 | + cast, |
| 23 | +) |
14 | 24 | import warnings
|
15 | 25 | import zipfile
|
16 | 26 |
|
@@ -301,35 +311,25 @@ def write_to_compressed(compression, path, data, dest="test"):
|
301 | 311 | ------
|
302 | 312 | ValueError : An invalid compression value was passed in.
|
303 | 313 | """
|
| 314 | + args: Tuple[Any, ...] = (data,) |
| 315 | + mode = "wb" |
| 316 | + method = "write" |
| 317 | + compress_method: Callable |
| 318 | + |
304 | 319 | if compression == "zip":
|
305 | 320 | compress_method = zipfile.ZipFile
|
| 321 | + mode = "w" |
| 322 | + args = (dest, data) |
| 323 | + method = "writestr" |
306 | 324 | elif compression == "gzip":
|
307 |
| - # pandas\_testing.py:288: error: Incompatible types in assignment |
308 |
| - # (expression has type "Type[GzipFile]", variable has type |
309 |
| - # "Type[ZipFile]") |
310 |
| - compress_method = gzip.GzipFile # type: ignore[assignment] |
| 325 | + compress_method = gzip.GzipFile |
311 | 326 | elif compression == "bz2":
|
312 |
| - # pandas\_testing.py:290: error: Incompatible types in assignment |
313 |
| - # (expression has type "Type[BZ2File]", variable has type |
314 |
| - # "Type[ZipFile]") |
315 |
| - compress_method = bz2.BZ2File # type: ignore[assignment] |
| 327 | + compress_method = bz2.BZ2File |
316 | 328 | elif compression == "xz":
|
317 | 329 | compress_method = get_lzma_file(lzma)
|
318 | 330 | else:
|
319 | 331 | raise ValueError(f"Unrecognized compression type: {compression}")
|
320 | 332 |
|
321 |
| - if compression == "zip": |
322 |
| - mode = "w" |
323 |
| - args = (dest, data) |
324 |
| - method = "writestr" |
325 |
| - else: |
326 |
| - mode = "wb" |
327 |
| - # pandas\_testing.py:302: error: Incompatible types in assignment |
328 |
| - # (expression has type "Tuple[Any]", variable has type "Tuple[Any, |
329 |
| - # Any]") |
330 |
| - args = (data,) # type: ignore[assignment] |
331 |
| - method = "write" |
332 |
| - |
333 | 333 | with compress_method(path, mode=mode) as f:
|
334 | 334 | getattr(f, method)(*args)
|
335 | 335 |
|
|
0 commit comments