Skip to content

Commit ad63b97

Browse files
authored
[BUG]: Fix regression in read_table with delim_whitespace=True (#36560)
1 parent d04b343 commit ad63b97

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

doc/source/whatsnew/v1.1.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Fixed regressions
4040
- Fixed regression in :meth:`DataFrame.apply` with ``raw=True`` and user-function returning string (:issue:`35940`)
4141
- Fixed regression when setting empty :class:`DataFrame` column to a :class:`Series` in preserving name of index in frame (:issue:`36527`)
4242
- Fixed regression in :class:`Period` incorrect value for ordinal over the maximum timestamp (:issue:`36430`)
43+
- Fixed regression in :func:`read_table` raised ``ValueError`` when ``delim_whitespace`` was set to ``True`` (:issue:`35958`)
4344
- Fixed regression in :meth:`Series.dt.normalize` when normalizing pre-epoch dates the result was shifted one day (:issue:`36294`)
4445

4546
.. ---------------------------------------------------------------------------

pandas/io/parsers.py

+10
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,16 @@ def read_table(
757757
memory_map=False,
758758
float_precision=None,
759759
):
760+
# TODO: validation duplicated in read_csv
761+
if delim_whitespace and (delimiter is not None or sep != "\t"):
762+
raise ValueError(
763+
"Specified a delimiter with both sep and "
764+
"delim_whitespace=True; you can only specify one."
765+
)
766+
if delim_whitespace:
767+
# In this case sep is not used so we set it to the read_csv
768+
# default to avoid a ValueError
769+
sep = ","
760770
return read_csv(**locals())
761771

762772

pandas/tests/io/parser/test_common.py

+21
Original file line numberDiff line numberDiff line change
@@ -2200,3 +2200,24 @@ def test_read_csv_with_use_inf_as_na(all_parsers):
22002200
result = parser.read_csv(StringIO(data), header=None)
22012201
expected = DataFrame([1.0, np.nan, 3.0])
22022202
tm.assert_frame_equal(result, expected)
2203+
2204+
2205+
def test_read_table_delim_whitespace_default_sep(all_parsers):
2206+
# GH: 35958
2207+
f = StringIO("a b c\n1 -2 -3\n4 5 6")
2208+
parser = all_parsers
2209+
result = parser.read_table(f, delim_whitespace=True)
2210+
expected = DataFrame({"a": [1, 4], "b": [-2, 5], "c": [-3, 6]})
2211+
tm.assert_frame_equal(result, expected)
2212+
2213+
2214+
def test_read_table_delim_whitespace_non_default_sep(all_parsers):
2215+
# GH: 35958
2216+
f = StringIO("a b c\n1 -2 -3\n4 5 6")
2217+
parser = all_parsers
2218+
msg = (
2219+
"Specified a delimiter with both sep and "
2220+
"delim_whitespace=True; you can only specify one."
2221+
)
2222+
with pytest.raises(ValueError, match=msg):
2223+
parser.read_table(f, delim_whitespace=True, sep=",")

0 commit comments

Comments
 (0)