Skip to content

Commit 6e0f3f1

Browse files
author
Oleh Kozynets
committed
Code review fixes.
1 parent 7cbfcef commit 6e0f3f1

File tree

2 files changed

+9
-38
lines changed

2 files changed

+9
-38
lines changed

pandas/io/parsers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,7 @@ def read_csv(
613613
# the comparison to dialect values by checking if default values
614614
# for BOTH "delimiter" and "sep" were provided.
615615
if dialect is not None:
616-
sep_override = (delimiter is None) and (sep is lib.no_default
617-
or sep == ",")
616+
sep_override = (delimiter is None) and (sep is lib.no_default or sep == ",")
618617
kwds = dict(sep_override=sep_override)
619618
else:
620619
kwds = dict()

pandas/tests/io/parser/test_common.py

+8-36
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,8 @@ def test_read_table_delim_whitespace_default_sep(all_parsers):
22112211
tm.assert_frame_equal(result, expected)
22122212

22132213

2214-
def test_read_csv_delim_whitespace_non_default_sep(all_parsers):
2214+
@pytest.mark.parametrize("delimiter", [",", "\t"])
2215+
def test_read_csv_delim_whitespace_non_default_sep(all_parsers, delimiter):
22152216
# GH: 35958
22162217
f = StringIO("a b c\n1 -2 -3\n4 5 6")
22172218
parser = all_parsers
@@ -2220,13 +2221,14 @@ def test_read_csv_delim_whitespace_non_default_sep(all_parsers):
22202221
"delim_whitespace=True; you can only specify one."
22212222
)
22222223
with pytest.raises(ValueError, match=msg):
2223-
parser.read_csv(f, delim_whitespace=True, sep="\t")
2224+
parser.read_csv(f, delim_whitespace=True, sep=delimiter)
22242225

22252226
with pytest.raises(ValueError, match=msg):
2226-
parser.read_csv(f, delim_whitespace=True, delimiter="\t")
2227+
parser.read_csv(f, delim_whitespace=True, delimiter=delimiter)
22272228

22282229

2229-
def test_read_table_delim_whitespace_non_default_sep(all_parsers):
2230+
@pytest.mark.parametrize("delimiter", [",", "\t"])
2231+
def test_read_table_delim_whitespace_non_default_sep(all_parsers, delimiter):
22302232
# GH: 35958
22312233
f = StringIO("a b c\n1 -2 -3\n4 5 6")
22322234
parser = all_parsers
@@ -2235,37 +2237,7 @@ def test_read_table_delim_whitespace_non_default_sep(all_parsers):
22352237
"delim_whitespace=True; you can only specify one."
22362238
)
22372239
with pytest.raises(ValueError, match=msg):
2238-
parser.read_table(f, delim_whitespace=True, sep=",")
2240+
parser.read_table(f, delim_whitespace=True, sep=delimiter)
22392241

22402242
with pytest.raises(ValueError, match=msg):
2241-
parser.read_table(f, delim_whitespace=True, delimiter=",")
2242-
2243-
2244-
def test_read_csv_delim_whitespace_explicit_default_sep(all_parsers):
2245-
# GH: 35958
2246-
f = StringIO("a b c\n1 -2 -3\n4 5 6")
2247-
parser = all_parsers
2248-
msg = (
2249-
"Specified a delimiter with both sep and "
2250-
"delim_whitespace=True; you can only specify one."
2251-
)
2252-
with pytest.raises(ValueError, match=msg):
2253-
parser.read_csv(f, delim_whitespace=True, sep=",")
2254-
2255-
with pytest.raises(ValueError, match=msg):
2256-
parser.read_csv(f, delim_whitespace=True, delimiter=",")
2257-
2258-
2259-
def test_read_table_delim_whitespace_explicit_default_sep(all_parsers):
2260-
# GH: 35958
2261-
f = StringIO("a b c\n1 -2 -3\n4 5 6")
2262-
parser = all_parsers
2263-
msg = (
2264-
"Specified a delimiter with both sep and "
2265-
"delim_whitespace=True; you can only specify one."
2266-
)
2267-
with pytest.raises(ValueError, match=msg):
2268-
parser.read_table(f, delim_whitespace=True, sep="\t")
2269-
2270-
with pytest.raises(ValueError, match=msg):
2271-
parser.read_table(f, delim_whitespace=True, delimiter="\t")
2243+
parser.read_table(f, delim_whitespace=True, delimiter=delimiter)

0 commit comments

Comments
 (0)