Skip to content

Commit a831405

Browse files
committed
Fix types
1 parent 8fa8b7f commit a831405

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pandas/conftest.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
)
4545

4646
try:
47-
import zstandard as zstd
47+
import zstandard as zstd # noqa: F401
48+
49+
have_zstd = True
4850
except ImportError:
49-
zstd = None
51+
have_zstd = False
5052

5153
import pandas.util._test_decorators as td
5254

@@ -271,15 +273,17 @@ def other_closed(request):
271273
return request.param
272274

273275

274-
@pytest.fixture(params=[None, "gzip", "bz2", "zip", "xz"] + (["zstd"] if zstd else []))
276+
@pytest.fixture(
277+
params=[None, "gzip", "bz2", "zip", "xz"] + (["zstd"] if have_zstd else [])
278+
)
275279
def compression(request):
276280
"""
277281
Fixture for trying common compression types in compression tests.
278282
"""
279283
return request.param
280284

281285

282-
@pytest.fixture(params=["gzip", "bz2", "zip", "xz"] + (["zstd"] if zstd else []))
286+
@pytest.fixture(params=["gzip", "bz2", "zip", "xz"] + (["zstd"] if have_zstd else []))
283287
def compression_only(request):
284288
"""
285289
Fixture for trying common compression types in compression tests excluding

pandas/tests/io/xml/test_xml.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
try:
1616
from zstandard import ZstdError
17+
18+
have_zstd = True
1719
except ImportError:
18-
ZstdError = None
20+
have_zstd = False
1921

2022
import pandas.util._test_decorators as td
2123

@@ -1037,13 +1039,15 @@ def test_wrong_compression(parser, compression, compression_only):
10371039
if actual_compression == attempted_compression:
10381040
return
10391041

1040-
error_cls, error_str = {
1042+
errors = {
10411043
"bz2": (OSError, "Invalid data stream"),
10421044
"gzip": (OSError, "Not a gzipped file"),
10431045
"xz": (LZMAError, "Input format not supported by decoder"),
10441046
"zip": (BadZipFile, "File is not a zip file"),
1045-
"zstd": (ZstdError, "Unknown frame descriptor"),
1046-
}[attempted_compression]
1047+
}
1048+
if have_zstd:
1049+
errors["zstd"] = (ZstdError, "Unknown frame descriptor")
1050+
error_cls, error_str = errors[attempted_compression]
10471051

10481052
with tm.ensure_clean() as path:
10491053
geom_df.to_xml(path, parser=parser, compression=actual_compression)

0 commit comments

Comments
 (0)