DEPR: read_table · Issue #21948 · pandas-dev/pandas (original) (raw)
Went through #18262 looking for an easy task, and deprecating read_table
looked like one. Currently, there's a function factory _make_parser_function
which produces both read_csv
and read_table
here:
read_csv = _make_parser_function('read_csv', sep=',') read_csv = Appender(_read_csv_doc)(read_csv)
read_table = _make_parser_function('read_table', sep='\t') read_table = Appender(_read_table_doc)(read_table)
Seems to me the simplest solution is wrapping read_table
like this:
def depr_read_table(func): """Deprecates read_table.""" from functools import wraps @wraps(read_table) def depr_func(*args, **kwargs): if len(args) > 1 or "sep" in kwargs or "delimiter" in kwargs: warnings.warn("read_table is deprecated, use read_csv instead", FutureWarning, stacklevel=2) else: warnings.warn("read_table is deprecated, use read_csv with " "sep='\t' instead", FutureWarning, stacklevel=2) return func(*args, **kwargs) return depr_func read_table = depr_read_table(read_table)
I would have to find out how to change the docs to declare the function deprecated, but I suppose that is easy...?
Result:
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({"a": [1], "b": [2]})
In [3]: df.to_csv("test.csv", sep="\t")
In [4]: pd.read_table("test.csv", index_col=0) /home/dahlbaek/virtualenvs/pandas-dev/bin/ipython:1: FutureWarning: read_table is deprecated, use read_csv with sep='\t' instead #!/home/dahlbaek/virtualenvs/pandas-dev/bin/python Out[4]: a b 0 1 2
In [5]: pd.read_table("test.csv", "\t", index_col=0) /home/dahlbaek/virtualenvs/pandas-dev/bin/ipython:1: FutureWarning: read_table is deprecated, use read_csv instead #!/home/dahlbaek/virtualenvs/pandas-dev/bin/python Out[5]: a b 0 1 2
In [6]: pd.read_table("test.csv", sep="\t", index_col=0) /home/dahlbaek/virtualenvs/pandas-dev/bin/ipython:1: FutureWarning: read_table is deprecated, use read_csv instead #!/home/dahlbaek/virtualenvs/pandas-dev/bin/python Out[6]: a b 0 1 2
In [7]: pd.read_table("test.csv", delimiter="\t", index_col=0) /home/dahlbaek/virtualenvs/pandas-dev/bin/ipython:1: FutureWarning: read_table is deprecated, use read_csv instead #!/home/dahlbaek/virtualenvs/pandas-dev/bin/python Out[7]: a b 0 1 2
In [8]: df Out[8]: a b 0 1 2
Any thoughts?