Skip to content

BUG: usecols kwarg accepts string when it should only allow list-like or callable. #20558

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

Merged
merged 10 commits into from
Apr 1, 2018
Prev Previous commit
Next Next commit
update parameter description to list-like
  • Loading branch information
minggli committed Mar 30, 2018
commit 2de72b17f408729f5c8e548efcf83d3db0c057ed
8 changes: 4 additions & 4 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@
MultiIndex is used. If you have a malformed file with delimiters at the end
of each line, you might consider index_col=False to force pandas to _not_
use the first column as the index (row names)
usecols : array-like or callable, default None
Return a subset of the columns. If array-like, all elements must either
usecols : list-like or callable, default None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this alone actually. array-like will suffice.

Copy link
Contributor Author

@minggli minggli Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. but below is_array_like will evaluate ['foo' ,'bar'] to False. so it's really a list-like IMHO.

def is_array_like(obj):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm...that's a fair point. Actually, leave that alone then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you're going to change it here, make sure to do it in io.rst as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. it's done.

Return a subset of the columns. If list-like, all elements must either
be positional (i.e. integer indices into the document columns) or strings
that correspond to column names provided either by the user in `names` or
inferred from the document header row(s). For example, a valid array-like
inferred from the document header row(s). For example, a valid list-like
`usecols` parameter would be [0, 1, 2] or ['foo', 'bar', 'baz']. Element
order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``.
To instantiate a DataFrame from ``data`` with element order preserved use
Expand Down Expand Up @@ -1177,7 +1177,7 @@ def _validate_usecols_arg(usecols):

Parameters
----------
usecols : array-like, callable, or None
usecols : list-like, callable, or None
List of columns to use when parsing or a callable that can be used
to filter a list of table columns.

Expand Down