Skip to content

Commit 42538f1

Browse files
jbrockmendelproost
authored andcommitted
DEPR: MultiIndex.to_hierarchical, labels (pandas-dev#29766)
1 parent 3041b6b commit 42538f1

File tree

16 files changed

+74
-249
lines changed

16 files changed

+74
-249
lines changed

ci/deps/azure-macos-36.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ dependencies:
2020
- matplotlib=2.2.3
2121
- nomkl
2222
- numexpr
23-
- numpy=1.13.3
23+
- numpy=1.14
2424
- openpyxl
25-
- pyarrow
25+
- pyarrow>=0.12.0
2626
- pytables
2727
- python-dateutil==2.6.1
2828
- pytz

ci/deps/azure-windows-36.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies:
2020
- numexpr
2121
- numpy=1.15.*
2222
- openpyxl
23-
- pyarrow
23+
- pyarrow>=0.12.0
2424
- pytables
2525
- python-dateutil
2626
- pytz

doc/redirects.csv

-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ generated/pandas.MultiIndex.sortlevel,../reference/api/pandas.MultiIndex.sortlev
828828
generated/pandas.MultiIndex.swaplevel,../reference/api/pandas.MultiIndex.swaplevel
829829
generated/pandas.MultiIndex.to_flat_index,../reference/api/pandas.MultiIndex.to_flat_index
830830
generated/pandas.MultiIndex.to_frame,../reference/api/pandas.MultiIndex.to_frame
831-
generated/pandas.MultiIndex.to_hierarchical,../reference/api/pandas.MultiIndex.to_hierarchical
832831
generated/pandas.notna,../reference/api/pandas.notna
833832
generated/pandas.notnull,../reference/api/pandas.notnull
834833
generated/pandas.option_context,../reference/api/pandas.option_context

doc/source/getting_started/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ matplotlib 2.2.2 Visualization
258258
openpyxl 2.4.8 Reading / writing for xlsx files
259259
pandas-gbq 0.8.0 Google Big Query access
260260
psycopg2 PostgreSQL engine for sqlalchemy
261-
pyarrow 0.9.0 Parquet and feather reading / writing
261+
pyarrow 0.12.0 Parquet and feather reading / writing
262262
pymysql 0.7.11 MySQL engine for sqlalchemy
263263
pyreadstat SPSS files (.sav) reading
264264
pytables 3.4.2 HDF5 reading / writing

doc/source/reference/indexing.rst

-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ MultiIndex components
305305

306306
MultiIndex.set_levels
307307
MultiIndex.set_codes
308-
MultiIndex.to_hierarchical
309308
MultiIndex.to_flat_index
310309
MultiIndex.to_frame
311310
MultiIndex.is_lexsorted

doc/source/whatsnew/v1.0.0.rst

+54-49
Original file line numberDiff line numberDiff line change
@@ -265,62 +265,62 @@ The following methods now also correctly output values for unobserved categories
265265
Increased minimum versions for dependencies
266266
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
267267

268-
Some minimum supported versions of dependencies were updated (:issue:`29723`).
268+
Some minimum supported versions of dependencies were updated (:issue:`29766`, :issue:`29723`).
269269
If installed, we now require:
270270

271-
+-----------------+-----------------+----------+
272-
| Package | Minimum Version | Required |
273-
+=================+=================+==========+
274-
| numpy | 1.13.3 | X |
275-
+-----------------+-----------------+----------+
276-
| pytz | 2015.4 | X |
277-
+-----------------+-----------------+----------+
278-
| python-dateutil | 2.6.1 | X |
279-
+-----------------+-----------------+----------+
280-
| bottleneck | 1.2.1 | |
281-
+-----------------+-----------------+----------+
282-
| numexpr | 2.6.2 | |
283-
+-----------------+-----------------+----------+
284-
| pytest (dev) | 4.0.2 | |
285-
+-----------------+-----------------+----------+
271+
+-----------------+-----------------+----------+---------+
272+
| Package | Minimum Version | Required | Changed |
273+
+=================+=================+==========+=========+
274+
| numpy | 1.13.3 | X | |
275+
+-----------------+-----------------+----------+---------+
276+
| pytz | 2015.4 | X | |
277+
+-----------------+-----------------+----------+---------+
278+
| python-dateutil | 2.6.1 | X | |
279+
+-----------------+-----------------+----------+---------+
280+
| bottleneck | 1.2.1 | | |
281+
+-----------------+-----------------+----------+---------+
282+
| numexpr | 2.6.2 | | |
283+
+-----------------+-----------------+----------+---------+
284+
| pytest (dev) | 4.0.2 | | |
285+
+-----------------+-----------------+----------+---------+
286286

287287
For `optional libraries <https://dev.pandas.io/docs/install.html#dependencies>`_ the general recommendation is to use the latest version.
288288
The following table lists the lowest version per library that is currently being tested throughout the development of pandas.
289289
Optional libraries below the lowest tested version may still work, but are not considered supported.
290290

291-
+-----------------+-----------------+
292-
| Package | Minimum Version |
293-
+=================+=================+
294-
| beautifulsoup4 | 4.6.0 |
295-
+-----------------+-----------------+
296-
| fastparquet | 0.3.2 |
297-
+-----------------+-----------------+
298-
| gcsfs | 0.2.2 |
299-
+-----------------+-----------------+
300-
| lxml | 3.8.0 |
301-
+-----------------+-----------------+
302-
| matplotlib | 2.2.2 |
303-
+-----------------+-----------------+
304-
| openpyxl | 2.4.8 |
305-
+-----------------+-----------------+
306-
| pyarrow | 0.9.0 |
307-
+-----------------+-----------------+
308-
| pymysql | 0.7.1 |
309-
+-----------------+-----------------+
310-
| pytables | 3.4.2 |
311-
+-----------------+-----------------+
312-
| scipy | 0.19.0 |
313-
+-----------------+-----------------+
314-
| sqlalchemy | 1.1.4 |
315-
+-----------------+-----------------+
316-
| xarray | 0.8.2 |
317-
+-----------------+-----------------+
318-
| xlrd | 1.1.0 |
319-
+-----------------+-----------------+
320-
| xlsxwriter | 0.9.8 |
321-
+-----------------+-----------------+
322-
| xlwt | 1.2.0 |
323-
+-----------------+-----------------+
291+
+-----------------+-----------------+---------+
292+
| Package | Minimum Version | Changed |
293+
+=================+=================+=========+
294+
| beautifulsoup4 | 4.6.0 | |
295+
+-----------------+-----------------+---------+
296+
| fastparquet | 0.3.2 | X |
297+
+-----------------+-----------------+---------+
298+
| gcsfs | 0.2.2 | |
299+
+-----------------+-----------------+---------+
300+
| lxml | 3.8.0 | |
301+
+-----------------+-----------------+---------+
302+
| matplotlib | 2.2.2 | |
303+
+-----------------+-----------------+---------+
304+
| openpyxl | 2.4.8 | |
305+
+-----------------+-----------------+---------+
306+
| pyarrow | 0.12.0 | X |
307+
+-----------------+-----------------+---------+
308+
| pymysql | 0.7.1 | |
309+
+-----------------+-----------------+---------+
310+
| pytables | 3.4.2 | |
311+
+-----------------+-----------------+---------+
312+
| scipy | 0.19.0 | |
313+
+-----------------+-----------------+---------+
314+
| sqlalchemy | 1.1.4 | |
315+
+-----------------+-----------------+---------+
316+
| xarray | 0.8.2 | |
317+
+-----------------+-----------------+---------+
318+
| xlrd | 1.1.0 | |
319+
+-----------------+-----------------+---------+
320+
| xlsxwriter | 0.9.8 | |
321+
+-----------------+-----------------+---------+
322+
| xlwt | 1.2.0 | |
323+
+-----------------+-----------------+---------+
324324

325325
See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more.
326326

@@ -415,6 +415,11 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
415415
- :func:`core.internals.blocks.make_block` no longer accepts the "fastpath" keyword(:issue:`19265`)
416416
- :meth:`Block.make_block_same_class` no longer accepts the "dtype" keyword(:issue:`19434`)
417417
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)
418+
- Removed the previously deprecated :meth:`MultiIndex.to_hierarchical` (:issue:`21613`)
419+
- Removed the previously deprecated :attr:`MultiIndex.labels`, use :attr:`MultiIndex.codes` instead (:issue:`23752`)
420+
- Removed the previously deprecated "labels" keyword from the :class:`MultiIndex` constructor, use "codes" instead (:issue:`23752`)
421+
- Removed the previously deprecated :meth:`MultiIndex.set_labels`, use :meth:`MultiIndex.set_codes` instead (:issue:`23752`)
422+
- Removed the previously deprecated "labels" keyword from :meth:`MultiIndex.set_codes`, :meth:`MultiIndex.copy`, :meth:`MultiIndex.drop`, use "codes" instead (:issue:`23752`)
418423
- Removed support for legacy HDF5 formats (:issue:`29787`)
419424
- :func:`read_excel` removed support for "skip_footer" argument, use "skipfooter" instead (:issue:`18836`)
420425
- :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`)

pandas/compat/_optional.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"odfpy": "1.3.0",
1717
"openpyxl": "2.4.8",
1818
"pandas_gbq": "0.8.0",
19-
"pyarrow": "0.9.0",
19+
"pyarrow": "0.12.0",
2020
"pytables": "3.4.2",
2121
"pytest": "5.0.1",
2222
"s3fs": "0.3.0",

pandas/core/indexes/base.py

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def _new_Index(cls, d):
160160
from pandas.core.indexes.period import _new_PeriodIndex
161161

162162
return _new_PeriodIndex(cls, **d)
163+
164+
if issubclass(cls, ABCMultiIndex):
165+
if "labels" in d and "codes" not in d:
166+
# GH#23752 "labels" kwarg has been replaced with "codes"
167+
d["codes"] = d.pop("labels")
168+
163169
return cls.__new__(cls, **d)
164170

165171

pandas/core/indexes/multi.py

+4-90
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pandas._libs.hashtable import duplicated_int64
1212
from pandas.compat.numpy import function as nv
1313
from pandas.errors import PerformanceWarning, UnsortedIndexError
14-
from pandas.util._decorators import Appender, cache_readonly, deprecate_kwarg
14+
from pandas.util._decorators import Appender, cache_readonly
1515

1616
from pandas.core.dtypes.common import (
1717
ensure_int64,
@@ -229,9 +229,7 @@ class MultiIndex(Index):
229229
of the mentioned helper methods.
230230
"""
231231

232-
_deprecations = Index._deprecations | frozenset(
233-
["labels", "set_labels", "to_hierarchical"]
234-
)
232+
_deprecations = Index._deprecations | frozenset()
235233

236234
# initialize to zero-length tuples to make everything work
237235
_typ = "multiindex"
@@ -244,7 +242,6 @@ class MultiIndex(Index):
244242
# --------------------------------------------------------------------
245243
# Constructors
246244

247-
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes")
248245
def __new__(
249246
cls,
250247
levels=None,
@@ -813,15 +810,6 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True):
813810
def codes(self):
814811
return self._codes
815812

816-
@property
817-
def labels(self):
818-
warnings.warn(
819-
(".labels was deprecated in version 0.24.0. Use .codes instead."),
820-
FutureWarning,
821-
stacklevel=2,
822-
)
823-
return self.codes
824-
825813
def _set_codes(
826814
self, codes, level=None, copy=False, validate=True, verify_integrity=False
827815
):
@@ -854,23 +842,6 @@ def _set_codes(
854842
self._tuples = None
855843
self._reset_cache()
856844

857-
def set_labels(self, labels, level=None, inplace=False, verify_integrity=True):
858-
warnings.warn(
859-
(
860-
".set_labels was deprecated in version 0.24.0. "
861-
"Use .set_codes instead."
862-
),
863-
FutureWarning,
864-
stacklevel=2,
865-
)
866-
return self.set_codes(
867-
codes=labels,
868-
level=level,
869-
inplace=inplace,
870-
verify_integrity=verify_integrity,
871-
)
872-
873-
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes")
874845
def set_codes(self, codes, level=None, inplace=False, verify_integrity=True):
875846
"""
876847
Set new codes on MultiIndex. Defaults to returning
@@ -947,7 +918,6 @@ def set_codes(self, codes, level=None, inplace=False, verify_integrity=True):
947918
if not inplace:
948919
return idx
949920

950-
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes")
951921
def copy(
952922
self,
953923
names=None,
@@ -981,7 +951,8 @@ def copy(
981951
"""
982952
name = kwargs.get("name")
983953
names = self._validate_names(name=name, names=names, deep=deep)
984-
954+
if "labels" in kwargs:
955+
raise TypeError("'labels' argument has been removed; use 'codes' instead")
985956
if deep:
986957
from copy import deepcopy
987958

@@ -1700,62 +1671,6 @@ def to_frame(self, index=True, name=None):
17001671
result.index = self
17011672
return result
17021673

1703-
def to_hierarchical(self, n_repeat, n_shuffle=1):
1704-
"""
1705-
Return a MultiIndex reshaped to conform to the
1706-
shapes given by n_repeat and n_shuffle.
1707-
1708-
.. deprecated:: 0.24.0
1709-
1710-
Useful to replicate and rearrange a MultiIndex for combination
1711-
with another Index with n_repeat items.
1712-
1713-
Parameters
1714-
----------
1715-
n_repeat : int
1716-
Number of times to repeat the labels on self.
1717-
n_shuffle : int
1718-
Controls the reordering of the labels. If the result is going
1719-
to be an inner level in a MultiIndex, n_shuffle will need to be
1720-
greater than one. The size of each label must divisible by
1721-
n_shuffle.
1722-
1723-
Returns
1724-
-------
1725-
MultiIndex
1726-
1727-
Examples
1728-
--------
1729-
>>> idx = pd.MultiIndex.from_tuples([(1, 'one'), (1, 'two'),
1730-
(2, 'one'), (2, 'two')])
1731-
>>> idx.to_hierarchical(3)
1732-
MultiIndex([(1, 'one'),
1733-
(1, 'one'),
1734-
(1, 'one'),
1735-
(1, 'two'),
1736-
(1, 'two'),
1737-
(1, 'two'),
1738-
(2, 'one'),
1739-
(2, 'one'),
1740-
(2, 'one'),
1741-
(2, 'two'),
1742-
(2, 'two'),
1743-
(2, 'two')],
1744-
)
1745-
"""
1746-
levels = self.levels
1747-
codes = [np.repeat(level_codes, n_repeat) for level_codes in self.codes]
1748-
# Assumes that each level_codes is divisible by n_shuffle
1749-
codes = [x.reshape(n_shuffle, -1).ravel(order="F") for x in codes]
1750-
names = self.names
1751-
warnings.warn(
1752-
"Method .to_hierarchical is deprecated and will "
1753-
"be removed in a future version",
1754-
FutureWarning,
1755-
stacklevel=2,
1756-
)
1757-
return MultiIndex(levels=levels, codes=codes, names=names)
1758-
17591674
def to_flat_index(self):
17601675
"""
17611676
Convert a MultiIndex to an Index of Tuples containing the level values.
@@ -2148,7 +2063,6 @@ def repeat(self, repeats, axis=None):
21482063
def where(self, cond, other=None):
21492064
raise NotImplementedError(".where is not supported for MultiIndex operations")
21502065

2151-
@deprecate_kwarg(old_arg_name="labels", new_arg_name="codes")
21522066
def drop(self, codes, level=None, errors="raise"):
21532067
"""
21542068
Make new MultiIndex with passed list of codes deleted

pandas/io/feather_format.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
""" feather-format compat """
22

3-
from distutils.version import LooseVersion
4-
53
from pandas.compat._optional import import_optional_dependency
64

75
from pandas import DataFrame, Int64Index, RangeIndex
@@ -96,15 +94,9 @@ def read_feather(path, columns=None, use_threads=True):
9694
-------
9795
type of object stored in file
9896
"""
99-
pyarrow = import_optional_dependency("pyarrow")
97+
import_optional_dependency("pyarrow")
10098
from pyarrow import feather
10199

102100
path = _stringify_path(path)
103101

104-
if LooseVersion(pyarrow.__version__) < LooseVersion("0.11.0"):
105-
int_use_threads = int(use_threads)
106-
if int_use_threads < 1:
107-
int_use_threads = 1
108-
return feather.read_feather(path, columns=columns, nthreads=int_use_threads)
109-
110102
return feather.read_feather(path, columns=columns, use_threads=bool(use_threads))

pandas/tests/extension/arrow/test_bool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pandas.tests.extension import base
66
import pandas.util.testing as tm
77

8-
pytest.importorskip("pyarrow", minversion="0.10.0")
8+
pytest.importorskip("pyarrow", minversion="0.12.0")
99

1010
from .arrays import ArrowBoolArray, ArrowBoolDtype # isort:skip
1111

pandas/tests/extension/arrow/test_string.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pandas as pd
44

5-
pytest.importorskip("pyarrow", minversion="0.10.0")
5+
pytest.importorskip("pyarrow", minversion="0.12.0")
66

77
from .arrays import ArrowStringDtype # isort:skip
88

0 commit comments

Comments
 (0)