Skip to content

Commit 14aedd3

Browse files
committed
update PR
1 parent ac7a6df commit 14aedd3

File tree

10 files changed

+33
-28
lines changed

10 files changed

+33
-28
lines changed

asv_bench/benchmarks/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ def setup(self):
473473
n1 = 400
474474
n2 = 250
475475
index = MultiIndex(levels=[np.arange(n1), tm.makeStringIndex(n2)],
476-
labels=[np.repeat(range(n1), n2).tolist(),
477-
list(range(n2)) * n1],
476+
codes=[np.repeat(range(n1), n2).tolist(),
477+
list(range(n2)) * n1],
478478
names=['lev1', 'lev2'])
479479
arr = np.random.randn(n1 * n2, 3)
480480
arr[::10000, 0] = np.nan

asv_bench/benchmarks/join_merge.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ class Join(object):
115115
def setup(self, sort):
116116
level1 = tm.makeStringIndex(10).values
117117
level2 = tm.makeStringIndex(1000).values
118-
label1 = np.arange(10).repeat(1000)
119-
label2 = np.tile(np.arange(1000), 10)
118+
codes1 = np.arange(10).repeat(1000)
119+
codes2 = np.tile(np.arange(1000), 10)
120120
index2 = MultiIndex(levels=[level1, level2],
121-
labels=[label1, label2])
121+
codes=[codes1, codes2])
122122
self.df_multi = DataFrame(np.random.randn(len(index2), 4),
123123
index=index2,
124124
columns=['A', 'B', 'C', 'D'])
125125

126-
self.key1 = np.tile(level1.take(label1), 10)
127-
self.key2 = np.tile(level2.take(label2), 10)
126+
self.key1 = np.tile(level1.take(codes1), 10)
127+
self.key2 = np.tile(level2.take(codes2), 10)
128128
self.df = DataFrame({'data1': np.random.randn(100000),
129129
'data2': np.random.randn(100000),
130130
'key1': self.key1,

asv_bench/benchmarks/reindex.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class LevelAlign(object):
7171
def setup(self):
7272
self.index = MultiIndex(
7373
levels=[np.arange(10), np.arange(100), np.arange(100)],
74-
labels=[np.arange(10).repeat(10000),
75-
np.tile(np.arange(100).repeat(100), 10),
76-
np.tile(np.tile(np.arange(100), 100), 10)])
74+
codes=[np.arange(10).repeat(10000),
75+
np.tile(np.arange(100).repeat(100), 10),
76+
np.tile(np.tile(np.arange(100), 100), 10)])
7777
self.df = DataFrame(np.random.randn(len(self.index), 4),
7878
index=self.index)
7979
self.df_level = DataFrame(np.random.randn(100, 4),

doc/source/whatsnew/v0.24.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,8 @@ Deprecations
11041104
The functionality is unchanged. This new name better reflects the natures of
11051105
these codes and makes the API more similar to the API for
11061106
:class:`CategoricalIndex`(:issue:`13443`).
1107-
As a concequence, other uses of the name ``labels`` have also been deprecated in ``MultiIndex`` and replaced with ``codes``:
1108-
- You should initialize a MultiIndex instance using a parameter named ``codes`` rather than ``labels``.
1107+
As a consequence, other uses of the name ``labels`` have also been deprecated in ``MultiIndex`` and replaced with ``codes``:
1108+
- You should initialize a ``MultiIndex`` instance using a parameter named ``codes`` rather than ``labels``.
11091109
- :meth:`MultiIndex.set_labels` has been deprecated in favor of :meth:`MultiIndex.set_codes`
11101110
- for method :meth:`MultiIndex.copy`, the ``labels`` parameter has been deprecated and replaced by a ``codes`` parameter.
11111111
- :meth:`DataFrame.to_stata`, :meth:`read_stata`, :class:`StataReader` and :class:`StataWriter` have deprecated the ``encoding`` argument. The encoding of a Stata dta file is determined by the file type and cannot be changed (:issue:`21244`)

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3840,8 +3840,8 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
38403840
38413841
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
38423842
... ['speed', 'weight', 'length']],
3843-
... labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3844-
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
3843+
... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3844+
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
38453845
>>> df = pd.DataFrame(index=midx, columns=['big', 'small'],
38463846
... data=[[45, 30], [200, 100], [1.5, 1], [30, 20],
38473847
... [250, 150], [1.5, 0.8], [320, 250],

pandas/core/indexes/multi.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def codes(self):
587587

588588
@property
589589
def labels(self):
590-
warnings.warn(("labels was deprecated in version 0.24.0. "
590+
warnings.warn((".labels was deprecated in version 0.24.0. "
591591
"Use .codes instead."),
592592
FutureWarning, stacklevel=2)
593593
return self.codes
@@ -622,7 +622,7 @@ def _set_codes(self, codes, level=None, copy=False, validate=True,
622622

623623
def set_labels(self, labels, level=None, inplace=False,
624624
verify_integrity=True):
625-
warnings.warn(("set_labels was deprecated in version 0.24.0. "
625+
warnings.warn((".set_labels was deprecated in version 0.24.0. "
626626
"Use .set_codes instead."),
627627
FutureWarning, stacklevel=2)
628628
return self.set_codes(codes=labels, level=level, inplace=inplace,
@@ -1512,7 +1512,7 @@ def _sort_levels_monotonic(self):
15121512
--------
15131513
15141514
>>> i = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1515-
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1515+
codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
15161516
>>> i
15171517
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
15181518
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
@@ -1885,7 +1885,7 @@ def swaplevel(self, i=-2, j=-1):
18851885
Examples
18861886
--------
18871887
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1888-
... labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1888+
... codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
18891889
>>> mi
18901890
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
18911891
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3670,8 +3670,8 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
36703670
36713671
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
36723672
... ['speed', 'weight', 'length']],
3673-
... labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3674-
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
3673+
... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3674+
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
36753675
>>> s = pd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
36763676
... index=midx)
36773677
>>> s

pandas/tests/indexes/multi/test_copy.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_labels_deprecated(idx):
4343
with tm.assert_produces_warning(FutureWarning):
4444
idx.copy(labels=codes)
4545

46+
4647
def test_view(idx):
4748
i_view = idx.view()
4849
assert_multiindex_copied(i_view, idx)

pandas/tests/indexes/multi/test_get_set.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def test_set_levels_codes_names_bad_input(idx):
348348
with pytest.raises(ValueError, match='Length of levels'):
349349
idx.set_levels([levels[0]])
350350

351-
with tm.assert_raises_regex(ValueError, 'Length of codes'):
351+
with pytest.raises(ValueError, match='Length of codes'):
352352
idx.set_codes([codes[0]])
353353

354354
with pytest.raises(ValueError, match='Length of names'):
@@ -359,7 +359,7 @@ def test_set_levels_codes_names_bad_input(idx):
359359
idx.set_levels(levels[0])
360360

361361
# shouldn't scalar data error, instead should demand list-like
362-
with tm.assert_raises_regex(TypeError, 'list of lists-like'):
362+
with pytest.raises(TypeError, match='list of lists-like'):
363363
idx.set_codes(codes[0])
364364

365365
# shouldn't scalar data error, instead should demand list-like

pandas/tests/io/test_feather.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@ def test_rw_nthreads(self):
100100
"the 'nthreads' keyword is deprecated, "
101101
"use 'use_threads' instead"
102102
)
103-
with tm.assert_produces_warning(FutureWarning) as w:
103+
# TODO: make the warning work with check_stacklevel=True
104+
with tm.assert_produces_warning(
105+
FutureWarning, check_stacklevel=False) as w:
104106
self.check_round_trip(df, nthreads=2)
105-
assert len(w) == 1
106-
assert expected_warning in str(w[0])
107+
# we have an extra FutureWarning because of #GH23752
108+
assert any(expected_warning in str(x) for x in w)
107109

108-
with tm.assert_produces_warning(FutureWarning) as w:
110+
# TODO: make the warning work with check_stacklevel=True
111+
with tm.assert_produces_warning(
112+
FutureWarning, check_stacklevel=False) as w:
109113
self.check_round_trip(df, nthreads=1)
110-
assert len(w) == 1
111-
assert expected_warning in str(w[0])
114+
# we have an extra FutureWarnings because of #GH23752
115+
assert any(expected_warning in str(x) for x in w)
112116

113117
def test_rw_use_threads(self):
114118
df = pd.DataFrame({'A': np.arange(100000)})

0 commit comments

Comments
 (0)