Skip to content

Commit 451fc5e

Browse files
committed
update PR
1 parent dc88457 commit 451fc5e

File tree

11 files changed

+33
-29
lines changed

11 files changed

+33
-29
lines changed

asv_bench/benchmarks/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ def setup(self):
471471
n1 = 400
472472
n2 = 250
473473
index = MultiIndex(levels=[np.arange(n1), tm.makeStringIndex(n2)],
474-
labels=[np.repeat(range(n1), n2).tolist(),
475-
list(range(n2)) * n1],
474+
codes=[np.repeat(range(n1), n2).tolist(),
475+
list(range(n2)) * n1],
476476
names=['lev1', 'lev2'])
477477
arr = np.random.randn(n1 * n2, 3)
478478
arr[::10000, 0] = np.nan

asv_bench/benchmarks/join_merge.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ class Join(object):
119119
def setup(self, sort):
120120
level1 = tm.makeStringIndex(10).values
121121
level2 = tm.makeStringIndex(1000).values
122-
label1 = np.arange(10).repeat(1000)
123-
label2 = np.tile(np.arange(1000), 10)
122+
codes1 = np.arange(10).repeat(1000)
123+
codes2 = np.tile(np.arange(1000), 10)
124124
index2 = MultiIndex(levels=[level1, level2],
125-
labels=[label1, label2])
125+
codes=[codes1, codes2])
126126
self.df_multi = DataFrame(np.random.randn(len(index2), 4),
127127
index=index2,
128128
columns=['A', 'B', 'C', 'D'])
129129

130-
self.key1 = np.tile(level1.take(label1), 10)
131-
self.key2 = np.tile(level2.take(label2), 10)
130+
self.key1 = np.tile(level1.take(codes1), 10)
131+
self.key2 = np.tile(level2.take(codes2), 10)
132132
self.df = DataFrame({'data1': np.random.randn(100000),
133133
'data2': np.random.randn(100000),
134134
'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
@@ -1022,8 +1022,8 @@ Deprecations
10221022
The functionality is unchanged. This new name better reflects the natures of
10231023
these codes and makes the API more similar to the API for
10241024
:class:`CategoricalIndex`(:issue:`13443`).
1025-
As a concequence, other uses of the name ``labels`` have also been deprecated in ``MultiIndex`` and replaced with ``codes``:
1026-
- You should initialize a MultiIndex instance using a parameter named ``codes`` rather than ``labels``.
1025+
As a consequence, other uses of the name ``labels`` have also been deprecated in ``MultiIndex`` and replaced with ``codes``:
1026+
- You should initialize a ``MultiIndex`` instance using a parameter named ``codes`` rather than ``labels``.
10271027
- :meth:`MultiIndex.set_labels` has been deprecated in favor of :meth:`MultiIndex.set_codes`
10281028
- for method :meth:`MultiIndex.copy`, the ``labels`` parameter has been deprecated and replaced by a ``codes`` parameter.
10291029
- :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
@@ -3785,8 +3785,8 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
37853785
37863786
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
37873787
... ['speed', 'weight', 'length']],
3788-
... labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3789-
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
3788+
... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3789+
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
37903790
>>> df = pd.DataFrame(index=midx, columns=['big', 'small'],
37913791
... data=[[45, 30], [200, 100], [1.5, 1], [30, 20],
37923792
... [250, 150], [1.5, 0.8], [320, 250],

pandas/core/indexes/multi.py

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

429429
@property
430430
def labels(self):
431-
warnings.warn(("labels was deprecated in version 0.24.0. "
431+
warnings.warn((".labels was deprecated in version 0.24.0. "
432432
"Use .codes instead."),
433433
FutureWarning, stacklevel=2)
434434
return self.codes
@@ -463,7 +463,7 @@ def _set_codes(self, codes, level=None, copy=False, validate=True,
463463

464464
def set_labels(self, labels, level=None, inplace=False,
465465
verify_integrity=True):
466-
warnings.warn(("set_labels was deprecated in version 0.24.0. "
466+
warnings.warn((".set_labels was deprecated in version 0.24.0. "
467467
"Use .set_codes instead."),
468468
FutureWarning, stacklevel=2)
469469
return self.set_codes(codes=labels, level=level, inplace=inplace,
@@ -1494,7 +1494,7 @@ def _sort_levels_monotonic(self):
14941494
--------
14951495
14961496
>>> i = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1497-
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1497+
codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
14981498
>>> i
14991499
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
15001500
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
@@ -1869,7 +1869,7 @@ def swaplevel(self, i=-2, j=-1):
18691869
Examples
18701870
--------
18711871
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1872-
... labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1872+
... codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
18731873
>>> mi
18741874
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
18751875
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3560,8 +3560,8 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
35603560
35613561
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
35623562
... ['speed', 'weight', 'length']],
3563-
... labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3564-
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
3563+
... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
3564+
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
35653565
>>> s = pd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
35663566
... index=midx)
35673567
>>> 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
@@ -87,15 +87,19 @@ def test_rw_nthreads(self):
8787
"the 'nthreads' keyword is deprecated, "
8888
"use 'use_threads' instead"
8989
)
90-
with tm.assert_produces_warning(FutureWarning) as w:
90+
# TODO: make the warning work with check_stacklevel=True
91+
with tm.assert_produces_warning(
92+
FutureWarning, check_stacklevel=False) as w:
9193
self.check_round_trip(df, nthreads=2)
92-
assert len(w) == 1
93-
assert expected_warning in str(w[0])
94+
# we have an extra FutureWarning because of #GH23752
95+
assert any(expected_warning in str(x) for x in w)
9496

95-
with tm.assert_produces_warning(FutureWarning) as w:
97+
# TODO: make the warning work with check_stacklevel=True
98+
with tm.assert_produces_warning(
99+
FutureWarning, check_stacklevel=False) as w:
96100
self.check_round_trip(df, nthreads=1)
97-
assert len(w) == 1
98-
assert expected_warning in str(w[0])
101+
# we have an extra FutureWarnings because of #GH23752
102+
assert any(expected_warning in str(x) for x in w)
99103

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

pandas/tests/test_algos.py

-1
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,6 @@ def test_too_many_ndims(self):
14621462
with pytest.raises(TypeError, match=msg):
14631463
algos.rank(arr)
14641464

1465-
@pytest.mark.xfail(reason="MemoryError")
14661465
@pytest.mark.parametrize('values', [
14671466
np.arange(2**24 + 1),
14681467
np.arange(2**25 + 2).reshape(2**24 + 1, 2)],

0 commit comments

Comments
 (0)