Skip to content

Commit 23d53a1

Browse files
committed
DEPR: pd.read_table
- pd.read_table is deprecated and replaced by pd.read_csv. - add whatsnew note - change tests to test for warning messages - change DataFrame.from_csv to use pandas.read_csv instead of pandas.read_table - Change pandas.read_clipboard to use pandas.read_csv instead of pandas.read_table
1 parent 3cb64bd commit 23d53a1

18 files changed

+290
-106
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Deprecations
319319
- :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`).
320320
- :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
321321
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
322+
- :func:`pandas.read_table` is deprecated. Use ``pandas.read_csv`` instead (:issue:`21948`)
322323
-
323324

324325
.. _whatsnew_0240.prior_deprecations:

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,8 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True,
15921592
"for from_csv when changing your function calls",
15931593
FutureWarning, stacklevel=2)
15941594

1595-
from pandas.io.parsers import read_table
1596-
return read_table(path, header=header, sep=sep,
1595+
from pandas.io.parsers import read_csv
1596+
return read_csv(path, header=header, sep=sep,
15971597
parse_dates=parse_dates, index_col=index_col,
15981598
encoding=encoding, tupleize_cols=tupleize_cols,
15991599
infer_datetime_format=infer_datetime_format)

pandas/io/clipboards.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover
1111
r"""
12-
Read text from clipboard and pass to read_table. See read_table for the
12+
Read text from clipboard and pass to read_csv. See read_csv for the
1313
full argument list
1414
1515
Parameters
@@ -31,7 +31,7 @@ def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover
3131
'reading from clipboard only supports utf-8 encoding')
3232

3333
from pandas.io.clipboard import clipboard_get
34-
from pandas.io.parsers import read_table
34+
from pandas.io.parsers import read_csv
3535
text = clipboard_get()
3636

3737
# try to decode (if needed on PY3)
@@ -51,7 +51,7 @@ def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover
5151
# that this came from excel and set 'sep' accordingly
5252
lines = text[:10000].split('\n')[:-1][:10]
5353

54-
# Need to remove leading white space, since read_table
54+
# Need to remove leading white space, since read_csv
5555
# accepts:
5656
# a b
5757
# 0 1 2
@@ -80,7 +80,7 @@ def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover
8080
if kwargs.get('engine') == 'python' and PY2:
8181
text = text.encode('utf-8')
8282

83-
return read_table(StringIO(text), sep=sep, **kwargs)
83+
return read_csv(StringIO(text), sep=sep, **kwargs)
8484

8585

8686
def to_clipboard(obj, excel=True, sep=None, **kwargs): # pragma: no cover

pandas/io/parsers.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@
326326
""" % (_parser_params % (_sep_doc.format(default="','"), _engine_doc))
327327

328328
_read_table_doc = """
329+
330+
.. deprecated:: 0.24.0
331+
Use :func:`pandas.read_csv` instead, passing `sep='\t'` if necessary.
332+
329333
Read general delimited file into DataFrame
330334
331335
%s
@@ -539,6 +543,10 @@ def _make_parser_function(name, sep=','):
539543

540544
default_sep = sep
541545

546+
# prepare read_table deprecation
547+
if name == "read_table":
548+
sep = False
549+
542550
def parser_f(filepath_or_buffer,
543551
sep=sep,
544552
delimiter=None,
@@ -606,11 +614,24 @@ def parser_f(filepath_or_buffer,
606614
memory_map=False,
607615
float_precision=None):
608616

617+
# deprecate read_table
618+
if name == "read_table":
619+
if sep is False and delimiter is None:
620+
warnings.warn("read_table is deprecated, use read_csv "
621+
"with sep='\\t' instead.",
622+
FutureWarning, stacklevel=2)
623+
else:
624+
warnings.warn("read_table is deprecated, use read_csv "
625+
"instead.",
626+
FutureWarning, stacklevel=2)
627+
if sep is False:
628+
sep = '\t'
629+
609630
# Alias sep -> delimiter.
610631
if delimiter is None:
611632
delimiter = sep
612633

613-
if delim_whitespace and delimiter is not default_sep:
634+
if delim_whitespace and delimiter != default_sep:
614635
raise ValueError("Specified a delimiter with both sep and"
615636
" delim_whitespace=True; you can only"
616637
" specify one.")

pandas/tests/io/conftest.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from pandas.io.parsers import read_table
3+
import pandas.util.testing as tm
34

45

56
@pytest.fixture
@@ -17,7 +18,10 @@ def jsonl_file(datapath):
1718
@pytest.fixture
1819
def salaries_table(datapath):
1920
"""DataFrame with the salaries dataset"""
20-
return read_table(datapath('io', 'parser', 'data', 'salaries.csv'))
21+
with tm.assert_produces_warning(FutureWarning,
22+
check_stacklevel=False):
23+
df = read_table(datapath('io', 'parser', 'data', 'salaries.csv'))
24+
return df
2125

2226

2327
@pytest.fixture

pandas/tests/io/formats/test_format.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,10 @@ def test_to_string(self):
12251225
lines = result.split('\n')
12261226
header = lines[0].strip().split()
12271227
joined = '\n'.join(re.sub(r'\s+', ' ', x).strip() for x in lines[1:])
1228-
recons = read_table(StringIO(joined), names=header,
1229-
header=None, sep=' ')
1228+
with tm.assert_produces_warning(FutureWarning,
1229+
check_stacklevel=False):
1230+
recons = read_table(StringIO(joined), names=header,
1231+
header=None, sep=' ')
12301232
tm.assert_series_equal(recons['B'], biggie['B'])
12311233
assert recons['A'].count() == biggie['A'].count()
12321234
assert (np.abs(recons['A'].dropna() -

pandas/tests/io/parser/c_parser_only.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def test_buffer_overflow(self, malf):
3434
# buffer overflows in tokenizer.c
3535
cperr = 'Buffer overflow caught - possible malformed input file.'
3636
with pytest.raises(pd.errors.ParserError) as excinfo:
37-
self.read_table(StringIO(malf))
37+
with tm.assert_produces_warning(FutureWarning,
38+
check_stacklevel=False):
39+
self.read_table(StringIO(malf))
3840
assert cperr in str(excinfo.value)
3941

4042
def test_buffer_rd_bytes(self):

pandas/tests/io/parser/comment.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def test_comment(self):
2424
df = self.read_csv(StringIO(data), comment='#')
2525
tm.assert_numpy_array_equal(df.values, expected)
2626

27-
df = self.read_table(StringIO(data), sep=',', comment='#',
28-
na_values=['NaN'])
27+
with tm.assert_produces_warning(FutureWarning,
28+
check_stacklevel=False):
29+
df = self.read_table(StringIO(data), sep=',', comment='#',
30+
na_values=['NaN'])
2931
tm.assert_numpy_array_equal(df.values, expected)
3032

3133
def test_line_comment(self):

0 commit comments

Comments
 (0)