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 · Fixed by #21954
Closed

DEPR: read_table #21948

dahlbaek opened this issue Jul 17, 2018 · 3 comments · Fixed by #21954
Labels
Deprecate Functionality to remove in pandas IO Data IO issues that don't fit into a more specific label
Milestone

Comments

@dahlbaek
Copy link
Contributor

dahlbaek 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
Copy link
Contributor Author

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 gfyoung added IO Data IO issues that don't fit into a more specific label Deprecate Functionality to remove in pandas labels Jul 17, 2018
@gfyoung
Copy link
Member

gfyoung 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
Copy link

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
Labels
Deprecate Functionality to remove in pandas IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants