Skip to content

Commit 1f01767

Browse files
jbrockmendelproost
authored andcommitted
DEPR: passing an int to read_excel use_cols (pandas-dev#29795)
1 parent 40a16dd commit 1f01767

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
391391
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)
392392
- Removed support for legacy HDF5 formats (:issue:`29787`)
393393
- :func:`read_excel` removed support for "skip_footer" argument, use "skipfooter" instead (:issue:`18836`)
394+
- :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`)
394395
- :meth:`DataFrame.to_records` no longer supports the argument "convert_datetime64" (:issue:`18902`)
395396
- Removed the previously deprecated ``IntervalIndex.from_intervals`` in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
396397
- Changed the default value for the "keep_tz" argument in :meth:`DatetimeIndex.to_series` to ``True`` (:issue:`23739`)

pandas/io/excel/_util.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
from pandas.compat._optional import import_optional_dependency
42

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

138136
if is_integer(usecols):
139-
warnings.warn(
140-
(
141-
"Passing in an integer for `usecols` has been "
142-
"deprecated. Please pass in a list of int from "
143-
"0 to `usecols` inclusive instead."
144-
),
145-
FutureWarning,
146-
stacklevel=2,
137+
raise ValueError(
138+
"Passing an integer for `usecols` is no longer supported. "
139+
"Please pass in a list of int from 0 to `usecols` "
140+
"inclusive instead."
147141
)
148-
return list(range(usecols + 1))
149142

150143
if isinstance(usecols, str):
151144
return _range2cols(usecols)

pandas/tests/io/excel/test_readers.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,18 @@ def test_usecols_int(self, read_ext, df_ref):
8888
df_ref = df_ref.reindex(columns=["A", "B", "C"])
8989

9090
# usecols as int
91-
with tm.assert_produces_warning(
92-
FutureWarning, check_stacklevel=False, raise_on_extra_warnings=False
93-
):
91+
msg = "Passing an integer for `usecols`"
92+
with pytest.raises(ValueError, match=msg):
9493
with ignore_xlrd_time_clock_warning():
95-
df1 = pd.read_excel(
96-
"test1" + read_ext, "Sheet1", index_col=0, usecols=3
97-
)
94+
pd.read_excel("test1" + read_ext, "Sheet1", index_col=0, usecols=3)
9895

9996
# usecols as int
100-
with tm.assert_produces_warning(
101-
FutureWarning, check_stacklevel=False, raise_on_extra_warnings=False
102-
):
97+
with pytest.raises(ValueError, match=msg):
10398
with ignore_xlrd_time_clock_warning():
104-
df2 = pd.read_excel(
99+
pd.read_excel(
105100
"test1" + read_ext, "Sheet2", skiprows=[1], index_col=0, usecols=3
106101
)
107102

108-
# TODO add index to xls file)
109-
tm.assert_frame_equal(df1, df_ref, check_names=False)
110-
tm.assert_frame_equal(df2, df_ref, check_names=False)
111-
112103
def test_usecols_list(self, read_ext, df_ref):
113104

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

0 commit comments

Comments
 (0)