Skip to content

Commit 3f62b90

Browse files
mroeschkephofl
authored andcommitted
DEPR: HDFStore.iteritems, read_csv(use_cols) behavior (pandas-dev#49483)
* Remove HDFStore iteritems * Enforce use_cols deprecation in read_csv * Spelling
1 parent 780e1fb commit 3f62b90

File tree

7 files changed

+14
-45
lines changed

7 files changed

+14
-45
lines changed

doc/source/whatsnew/v2.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Removal of prior version deprecations/changes
180180
- Enforced deprecation changing behavior when passing ``datetime64[ns]`` dtype data and timezone-aware dtype to :class:`Series`, interpreting the values as wall-times instead of UTC times, matching :class:`DatetimeIndex` behavior (:issue:`41662`)
181181
- Removed deprecated :meth:`DataFrame._AXIS_NUMBERS`, :meth:`DataFrame._AXIS_NAMES`, :meth:`Series._AXIS_NUMBERS`, :meth:`Series._AXIS_NAMES` (:issue:`33637`)
182182
- Removed deprecated :meth:`Index.to_native_types`, use ``obj.astype(str)`` instead (:issue:`36418`)
183-
- Removed deprecated :meth:`Series.iteritems`, :meth:`DataFrame.iteritems`, use ``obj.items`` instead (:issue:`45321`)
183+
- Removed deprecated :meth:`Series.iteritems`, :meth:`DataFrame.iteritems` and :meth:`HDFStore.iteritems` use ``obj.items`` instead (:issue:`45321`)
184184
- Removed deprecated :meth:`DatetimeIndex.union_many` (:issue:`45018`)
185185
- Removed deprecated ``weekofyear`` and ``week`` attributes of :class:`DatetimeArray`, :class:`DatetimeIndex` and ``dt`` accessor in favor of ``isocalendar().week`` (:issue:`33595`)
186186
- Removed deprecated :meth:`RangeIndex._start`, :meth:`RangeIndex._stop`, :meth:`RangeIndex._step`, use ``start``, ``stop``, ``step`` instead (:issue:`30482`)
@@ -289,6 +289,7 @@ Removal of prior version deprecations/changes
289289
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame``, including pickle support. (:issue:`30642`)
290290
- Enforced disallowing passing an integer ``fill_value`` to :meth:`DataFrame.shift` and :meth:`Series.shift`` with datetime64, timedelta64, or period dtypes (:issue:`32591`)
291291
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
292+
- Enforced disallowing using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
292293
- Enforced disallowing the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
293294
- Enforced disallowing a tuple of column labels into :meth:`.DataFrameGroupBy.__getitem__` (:issue:`30546`)
294295
- Enforced disallowing setting values with ``.loc`` using a positional slice. Use ``.loc`` with labels or ``.iloc`` with positions instead (:issue:`31840`)

pandas/_libs/parsers.pyx

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import sys
1313
import time
1414
import warnings
1515

16+
from pandas.errors import ParserError
1617
from pandas.util._exceptions import find_stack_level
1718

1819
from pandas import StringDtype
@@ -971,11 +972,9 @@ cdef class TextReader:
971972
all(isinstance(u, int) for u in self.usecols)):
972973
missing_usecols = [col for col in self.usecols if col >= num_cols]
973974
if missing_usecols:
974-
warnings.warn(
975-
"Defining usecols with out of bounds indices is deprecated "
976-
"and will raise a ParserError in a future version.",
977-
FutureWarning,
978-
stacklevel=find_stack_level(),
975+
raise ParserError(
976+
"Defining usecols without of bounds indices is not allowed. "
977+
f"{missing_usecols} are out of bounds.",
979978
)
980979

981980
results = {}

pandas/io/excel/_base.py

-2
Original file line numberDiff line numberDiff line change
@@ -1528,8 +1528,6 @@ class ExcelFile:
15281528
- Otherwise if `openpyxl <https://pypi.org/project/openpyxl/>`_ is installed,
15291529
then ``openpyxl`` will be used.
15301530
- Otherwise if ``xlrd >= 2.0`` is installed, a ``ValueError`` will be raised.
1531-
- Otherwise ``xlrd`` will be used and a ``FutureWarning`` will be raised.
1532-
This case will raise a ``ValueError`` in a future version of pandas.
15331531
15341532
.. warning::
15351533

pandas/io/parsers/python_parser.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
Sequence,
2121
cast,
2222
)
23-
import warnings
2423

2524
import numpy as np
2625

@@ -34,7 +33,6 @@
3433
EmptyDataError,
3534
ParserError,
3635
)
37-
from pandas.util._exceptions import find_stack_level
3836

3937
from pandas.core.dtypes.common import is_integer
4038
from pandas.core.dtypes.inference import is_dict_like
@@ -592,11 +590,9 @@ def _handle_usecols(
592590
col for col in self.usecols if col >= num_original_columns
593591
]
594592
if missing_usecols:
595-
warnings.warn(
596-
"Defining usecols with out of bounds indices is deprecated "
597-
"and will raise a ParserError in a future version.",
598-
FutureWarning,
599-
stacklevel=find_stack_level(),
593+
raise ParserError(
594+
"Defining usecols without of bounds indices is not allowed. "
595+
f"{missing_usecols} are out of bounds.",
600596
)
601597
col_indices = self.usecols
602598

pandas/io/pytables.py

-12
Original file line numberDiff line numberDiff line change
@@ -684,18 +684,6 @@ def items(self) -> Iterator[tuple[str, list]]:
684684
for g in self.groups():
685685
yield g._v_pathname, g
686686

687-
def iteritems(self):
688-
"""
689-
iterate on key->group
690-
"""
691-
warnings.warn(
692-
"iteritems is deprecated and will be removed in a future version. "
693-
"Use .items instead.",
694-
FutureWarning,
695-
stacklevel=find_stack_level(),
696-
)
697-
yield from self.items()
698-
699687
def open(self, mode: str = "a", **kwargs) -> None:
700688
"""
701689
Open the file in the specified mode

pandas/tests/io/parser/usecols/test_usecols_basic.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import numpy as np
88
import pytest
99

10+
from pandas.errors import ParserError
11+
1012
from pandas import (
1113
DataFrame,
1214
Index,
@@ -402,20 +404,14 @@ def test_usecols_subset_names_mismatch_orig_columns(all_parsers, usecols):
402404

403405
@pytest.mark.parametrize("names", [None, ["a", "b"]])
404406
def test_usecols_indices_out_of_bounds(all_parsers, names):
405-
# GH#25623
407+
# GH#25623 & GH 41130; enforced in 2.0
406408
parser = all_parsers
407409
data = """
408410
a,b
409411
1,2
410412
"""
411-
with tm.assert_produces_warning(
412-
FutureWarning, check_stacklevel=False, raise_on_extra_warnings=False
413-
):
414-
result = parser.read_csv(StringIO(data), usecols=[0, 2], names=names, header=0)
415-
expected = DataFrame({"a": [1], "b": [None]})
416-
if names is None and parser.engine == "python":
417-
expected = DataFrame({"a": [1]})
418-
tm.assert_frame_equal(result, expected)
413+
with pytest.raises(ParserError, match="Defining usecols without of bounds"):
414+
parser.read_csv(StringIO(data), usecols=[0, 2], names=names, header=0)
419415

420416

421417
def test_usecols_additional_columns(all_parsers):

pandas/tests/io/pytables/test_store.py

-9
Original file line numberDiff line numberDiff line change
@@ -1009,15 +1009,6 @@ def test_to_hdf_with_object_column_names(tmp_path, setup_path):
10091009
assert len(result)
10101010

10111011

1012-
def test_hdfstore_iteritems_deprecated(tmp_path, setup_path):
1013-
path = tmp_path / setup_path
1014-
df = DataFrame({"a": [1]})
1015-
with HDFStore(path, mode="w") as hdf:
1016-
hdf.put("table", df)
1017-
with tm.assert_produces_warning(FutureWarning):
1018-
next(hdf.iteritems())
1019-
1020-
10211012
def test_hdfstore_strides(setup_path):
10221013
# GH22073
10231014
df = DataFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})

0 commit comments

Comments
 (0)