Skip to content

Commit

Permalink
DEPR: pd.read_table
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dahlbaek committed Jul 18, 2018
1 parent 537b65c commit 15dfae8
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 98 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Deprecations
- :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`).
- :meth:`MultiIndex.to_hierarchical` is deprecated and will be removed in a future version (:issue:`21613`)
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
- :func:`pandas.read_table` is deprecated. Use ``pandas.read_csv`` instead (:issue:`21948`)
-

.. _whatsnew_0240.prior_deprecations:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,8 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True,
"for from_csv when changing your function calls",
FutureWarning, stacklevel=2)

from pandas.io.parsers import read_table
return read_table(path, header=header, sep=sep,
from pandas.io.parsers import read_csv
return read_csv(path, header=header, sep=sep,
parse_dates=parse_dates, index_col=index_col,
encoding=encoding, tupleize_cols=tupleize_cols,
infer_datetime_format=infer_datetime_format)
Expand Down
21 changes: 21 additions & 0 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@
""" % (_parser_params % (_sep_doc.format(default="','"), _engine_doc))

_read_table_doc = """
.. deprecated:: 0.24.0
Use :func:`pandas.read_csv` instead, passing `sep='\t'` if necessary.
Read general delimited file into DataFrame
%s
Expand Down Expand Up @@ -539,6 +543,10 @@ def _make_parser_function(name, sep=','):

default_sep = sep

# prepare read_table deprecation
if name == "read_table":
sep = False

def parser_f(filepath_or_buffer,
sep=sep,
delimiter=None,
Expand Down Expand Up @@ -606,6 +614,19 @@ def parser_f(filepath_or_buffer,
memory_map=False,
float_precision=None):

# deprecate read_table
if name == "read_table":
if sep is False and delimiter is None:
warnings.warn("read_table is deprecated, use read_csv "
"with sep='\\t' instead.",
FutureWarning, stacklevel=2)
else:
warnings.warn("read_table is deprecated, use read_csv "
"instead.",
FutureWarning, stacklevel=2)
if sep is False:
sep = '\t'

# Alias sep -> delimiter.
if delimiter is None:
delimiter = sep
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,9 @@ def test_to_string(self):
lines = result.split('\n')
header = lines[0].strip().split()
joined = '\n'.join(re.sub(r'\s+', ' ', x).strip() for x in lines[1:])
recons = read_table(StringIO(joined), names=header,
header=None, sep=' ')
with tm.assert_produces_warning(FutureWarning):
recons = read_table(StringIO(joined), names=header,
header=None, sep=' ')
tm.assert_series_equal(recons['B'], biggie['B'])
assert recons['A'].count() == biggie['A'].count()
assert (np.abs(recons['A'].dropna() -
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/io/parser/c_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def test_buffer_overflow(self, malf):
# buffer overflows in tokenizer.c
cperr = 'Buffer overflow caught - possible malformed input file.'
with pytest.raises(pd.errors.ParserError) as excinfo:
self.read_table(StringIO(malf))
with tm.assert_produces_warning(FutureWarning):
self.read_table(StringIO(malf))
assert cperr in str(excinfo.value)

def test_buffer_rd_bytes(self):
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/io/parser/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def test_comment(self):
df = self.read_csv(StringIO(data), comment='#')
tm.assert_numpy_array_equal(df.values, expected)

df = self.read_table(StringIO(data), sep=',', comment='#',
na_values=['NaN'])
with tm.assert_produces_warning(FutureWarning):
df = self.read_table(StringIO(data), sep=',', comment='#',
na_values=['NaN'])
tm.assert_numpy_array_equal(df.values, expected)

def test_line_comment(self):
Expand Down
Loading

0 comments on commit 15dfae8

Please sign in to comment.