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: passing an int to read_excel use_cols #29795

Merged
merged 1 commit into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)
- Removed support for legacy HDF5 formats (:issue:`29787`)
- :func:`read_excel` removed support for "skip_footer" argument, use "skipfooter" instead (:issue:`18836`)
- :func:`read_excel` no longer allows an integer value for the parameter ``usecols``, instead pass a list of integers from 0 to ``usecols`` inclusive (:issue:`23635`)
- :meth:`DataFrame.to_records` no longer supports the argument "convert_datetime64" (:issue:`18902`)
- Removed the previously deprecated ``IntervalIndex.from_intervals`` in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
- Changed the default value for the "keep_tz" argument in :meth:`DatetimeIndex.to_series` to ``True`` (:issue:`23739`)
Expand Down
15 changes: 4 additions & 11 deletions pandas/io/excel/_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import warnings

from pandas.compat._optional import import_optional_dependency

from pandas.core.dtypes.common import is_integer, is_list_like
Expand Down Expand Up @@ -136,16 +134,11 @@ def _maybe_convert_usecols(usecols):
return usecols

if is_integer(usecols):
warnings.warn(
(
"Passing in an integer for `usecols` has been "
"deprecated. Please pass in a list of int from "
"0 to `usecols` inclusive instead."
),
FutureWarning,
stacklevel=2,
raise ValueError(
"Passing an integer for `usecols` is no longer supported. "
"Please pass in a list of int from 0 to `usecols` "
"inclusive instead."
)
return list(range(usecols + 1))

if isinstance(usecols, str):
return _range2cols(usecols)
Expand Down
19 changes: 5 additions & 14 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,18 @@ def test_usecols_int(self, read_ext, df_ref):
df_ref = df_ref.reindex(columns=["A", "B", "C"])

# usecols as int
with tm.assert_produces_warning(
FutureWarning, check_stacklevel=False, raise_on_extra_warnings=False
):
msg = "Passing an integer for `usecols`"
with pytest.raises(ValueError, match=msg):
with ignore_xlrd_time_clock_warning():
df1 = pd.read_excel(
"test1" + read_ext, "Sheet1", index_col=0, usecols=3
)
pd.read_excel("test1" + read_ext, "Sheet1", index_col=0, usecols=3)

# usecols as int
with tm.assert_produces_warning(
FutureWarning, check_stacklevel=False, raise_on_extra_warnings=False
):
with pytest.raises(ValueError, match=msg):
with ignore_xlrd_time_clock_warning():
df2 = pd.read_excel(
pd.read_excel(
"test1" + read_ext, "Sheet2", skiprows=[1], index_col=0, usecols=3
)

# TODO add index to xls file)
tm.assert_frame_equal(df1, df_ref, check_names=False)
tm.assert_frame_equal(df2, df_ref, check_names=False)

def test_usecols_list(self, read_ext, df_ref):

df_ref = df_ref.reindex(columns=["B", "C"])
Expand Down