Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: read_table #21948

Closed
dahlbaek opened this issue Jul 17, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@dahlbaek
Copy link
Contributor

commented Jul 17, 2018

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?

@dahlbaek

This comment has been minimized.

Copy link
Contributor Author

commented Jul 17, 2018

I suppose declaring the function deprecated could be as simple as changing _read_table_doc here into

_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
""" % (_parser_params % (_sep_doc.format(default="\\t (tab-stop)"),
                         _engine_doc))```
@gfyoung

This comment has been minimized.

Copy link
Member

commented Jul 17, 2018

I would consider adding another parameter to _make_parser_function so that it adds the appropriate deprecation messages both in the code and in the docstring.

@st-bender

This comment has been minimized.

Copy link

commented Feb 1, 2019

Why not deprecate read_csv() instead? read_table() sounds more general and if they are basically the same, why not keep both as aliases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.