Skip to content

Commit 1b9beb4

Browse files
committed
CLN: Remove compat checks in tests/io/parser
xref pandas-devgh-25725
1 parent 85c3f82 commit 1b9beb4

File tree

3 files changed

+13
-35
lines changed

3 files changed

+13
-35
lines changed

pandas/tests/io/parser/test_common.py

+9-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections import OrderedDict
1010
import csv
1111
from datetime import datetime
12+
from io import TextIOWrapper
1213
import os
1314
import platform
1415
from tempfile import TemporaryFile
@@ -75,9 +76,6 @@ def _set_noconvert_columns(self):
7576

7677

7778
def test_bytes_io_input(all_parsers):
78-
if compat.PY2:
79-
pytest.skip("Bytes-related test does not need to work on Python 2.x")
80-
8179
encoding = "cp1255"
8280
parser = all_parsers
8381

@@ -112,8 +110,7 @@ def test_bad_stream_exception(all_parsers, csv_dir_path):
112110
utf8 = codecs.lookup('utf-8')
113111
parser = all_parsers
114112

115-
msg = ("'utf-8' codec can't decode byte" if compat.PY3
116-
else "'utf8' codec can't decode byte")
113+
msg = "'utf-8' codec can't decode byte"
117114

118115
# Stream must be binary UTF8.
119116
with open(path, "rb") as handle, codecs.StreamRecoder(
@@ -124,7 +121,6 @@ def test_bad_stream_exception(all_parsers, csv_dir_path):
124121
parser.read_csv(stream)
125122

126123

127-
@pytest.mark.skipif(compat.PY2, reason="PY3-only test")
128124
def test_read_csv_local(all_parsers, csv1):
129125
prefix = u("file:///") if compat.is_platform_windows() else u("file://")
130126
parser = all_parsers
@@ -963,10 +959,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
963959
f.write(bytes_data)
964960

965961
bytes_buffer = BytesIO(data.encode(utf8))
966-
967-
if compat.PY3:
968-
from io import TextIOWrapper
969-
bytes_buffer = TextIOWrapper(bytes_buffer, encoding=utf8)
962+
bytes_buffer = TextIOWrapper(bytes_buffer, encoding=utf8)
970963

971964
result = parser.read_csv(path, encoding=encoding, **kwargs)
972965
expected = parser.read_csv(bytes_buffer, encoding=utf8, **kwargs)
@@ -978,7 +971,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
978971
@pytest.mark.parametrize("buffer", [
979972
False,
980973
pytest.param(True, marks=pytest.mark.skipif(
981-
compat.PY3, reason="Not supported on PY3"))])
974+
True, reason="Not supported"))])
982975
def test_utf16_example(all_parsers, csv_dir_path, buffer):
983976
path = os.path.join(csv_dir_path, "utf16_ex.txt")
984977
parser = all_parsers
@@ -1565,22 +1558,17 @@ def test_iteration_open_handle(all_parsers):
15651558
kwargs = dict(squeeze=True, header=None)
15661559

15671560
with tm.ensure_clean() as path:
1568-
with open(path, "wb" if compat.PY2 else "w") as f:
1561+
with open(path, "w") as f:
15691562
f.write("AAA\nBBB\nCCC\nDDD\nEEE\nFFF\nGGG")
15701563

1571-
with open(path, "rb" if compat.PY2 else "r") as f:
1564+
with open(path, "r") as f:
15721565
for line in f:
15731566
if "CCC" in line:
15741567
break
15751568

1576-
if parser.engine == "c" and compat.PY2:
1577-
msg = "Mixing iteration and read methods would lose data"
1578-
with pytest.raises(ValueError, match=msg):
1579-
parser.read_csv(f, **kwargs)
1580-
else:
1581-
result = parser.read_csv(f, **kwargs)
1582-
expected = Series(["DDD", "EEE", "FFF", "GGG"], name=0)
1583-
tm.assert_series_equal(result, expected)
1569+
result = parser.read_csv(f, **kwargs)
1570+
expected = Series(["DDD", "EEE", "FFF", "GGG"], name=0)
1571+
tm.assert_series_equal(result, expected)
15841572

15851573

15861574
@pytest.mark.parametrize("data,thousands,decimal", [

pandas/tests/io/parser/test_python_parser_only.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"""
99

1010
import csv
11+
from io import TextIOWrapper
1112

1213
import pytest
1314

14-
import pandas.compat as compat
1515
from pandas.compat import BytesIO, StringIO, u
1616
from pandas.errors import ParserError
1717

@@ -83,11 +83,9 @@ def test_sniff_delimiter_encoding(python_parser_only, encoding):
8383

8484
if encoding is not None:
8585
data = u(data).encode(encoding)
86-
data = BytesIO(data)
8786

88-
if compat.PY3:
89-
from io import TextIOWrapper
90-
data = TextIOWrapper(data, encoding=encoding)
87+
data = BytesIO(data)
88+
data = TextIOWrapper(data, encoding=encoding)
9189
else:
9290
data = StringIO(data)
9391

pandas/tests/io/parser/test_read_fwf.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ def test_read_csv_compat():
161161

162162

163163
def test_bytes_io_input():
164-
if not compat.PY3:
165-
pytest.skip("Bytes-related test - only needs to work on Python 3")
166-
167164
result = read_fwf(BytesIO("שלום\nשלום".encode('utf8')),
168165
widths=[2, 2], encoding="utf8")
169166
expected = DataFrame([["של", "ום"]], columns=["של", "ום"])
@@ -441,9 +438,6 @@ def test_multiple_delimiters():
441438

442439

443440
def test_variable_width_unicode():
444-
if not compat.PY3:
445-
pytest.skip("Bytes-related test - only needs to work on Python 3")
446-
447441
data = """
448442
שלום שלום
449443
ום שלל
@@ -566,9 +560,7 @@ def test_fwf_compression(compression_only, infer):
566560

567561
kwargs = dict(widths=[5, 5], names=["one", "two"])
568562
expected = read_fwf(StringIO(data), **kwargs)
569-
570-
if compat.PY3:
571-
data = bytes(data, encoding="utf-8")
563+
data = bytes(data, encoding="utf-8")
572564

573565
with tm.ensure_clean(filename="tmp." + extension) as path:
574566
tm.write_to_compressed(compression, path, data)

0 commit comments

Comments
 (0)