Skip to content

Commit 19ea89a

Browse files
phoflTLouf
authored andcommitted
BUG: raise ValueError when sep and delimiter are defined in read_csv (pandas-dev#41146)
1 parent 1dbd326 commit 19ea89a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ I/O
974974
- Bug in :func:`read_orc` always raising ``AttributeError`` (:issue:`40918`)
975975
- Bug in :func:`read_csv` and :func:`read_table` silently ignoring ``prefix`` if ``names`` and ``prefix`` are defined, now raising ``ValueError`` (:issue:`39123`)
976976
- Bug in :func:`read_csv` and :func:`read_excel` not respecting dtype for duplicated column name when ``mangle_dupe_cols`` is set to ``True`` (:issue:`35211`)
977+
- Bug in :func:`read_csv` silently ignoring ``sep`` if ``delimiter`` and ``sep`` are defined, now raising ``ValueError`` (:issue:`39823`)
977978
- Bug in :func:`read_csv` and :func:`read_table` misinterpreting arguments when ``sys.setprofile`` had been previously called (:issue:`41069`)
978979
- Bug in the conversion from pyarrow to pandas (e.g. for reading Parquet) with nullable dtypes and a pyarrow array whose data buffer size is not a multiple of dtype size (:issue:`40896`)
979980
- Bug in :func:`read_excel` would raise an error when pandas could not determine the file type, even when user specified the ``engine`` argument (:issue:`41225`)

pandas/io/parsers/readers.py

+3
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,9 @@ def _refine_defaults_read(
12551255
sep is lib.no_default or sep == delim_default
12561256
)
12571257

1258+
if delimiter and (sep is not lib.no_default):
1259+
raise ValueError("Specified a sep and a delimiter; you can only specify one.")
1260+
12581261
if names is not lib.no_default and prefix is not lib.no_default:
12591262
raise ValueError("Specified named and prefix; you can only specify one.")
12601263

pandas/tests/io/parser/common/test_common_basic.py

+9
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,15 @@ def test_read_csv_delim_whitespace_non_default_sep(all_parsers, delimiter):
724724
parser.read_csv(f, delim_whitespace=True, delimiter=delimiter)
725725

726726

727+
def test_read_csv_delimiter_and_sep_no_default(all_parsers):
728+
# GH#39823
729+
f = StringIO("a,b\n1,2")
730+
parser = all_parsers
731+
msg = "Specified a sep and a delimiter; you can only specify one."
732+
with pytest.raises(ValueError, match=msg):
733+
parser.read_csv(f, sep=" ", delimiter=".")
734+
735+
727736
@pytest.mark.parametrize("delimiter", [",", "\t"])
728737
def test_read_table_delim_whitespace_non_default_sep(all_parsers, delimiter):
729738
# GH: 35958

0 commit comments

Comments
 (0)