Skip to content

Commit

Permalink
update PR
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Nov 18, 2018
1 parent 3399195 commit fc2c214
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ def setup(self):
n1 = 400
n2 = 250
index = MultiIndex(levels=[np.arange(n1), tm.makeStringIndex(n2)],
labels=[np.repeat(range(n1), n2).tolist(),
list(range(n2)) * n1],
codes=[np.repeat(range(n1), n2).tolist(),
list(range(n2)) * n1],
names=['lev1', 'lev2'])
arr = np.random.randn(n1 * n2, 3)
arr[::10000, 0] = np.nan
Expand Down
10 changes: 5 additions & 5 deletions asv_bench/benchmarks/join_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ class Join(object):
def setup(self, sort):
level1 = tm.makeStringIndex(10).values
level2 = tm.makeStringIndex(1000).values
label1 = np.arange(10).repeat(1000)
label2 = np.tile(np.arange(1000), 10)
codes1 = np.arange(10).repeat(1000)
codes2 = np.tile(np.arange(1000), 10)
index2 = MultiIndex(levels=[level1, level2],
labels=[label1, label2])
codes=[codes1, codes2])
self.df_multi = DataFrame(np.random.randn(len(index2), 4),
index=index2,
columns=['A', 'B', 'C', 'D'])

self.key1 = np.tile(level1.take(label1), 10)
self.key2 = np.tile(level2.take(label2), 10)
self.key1 = np.tile(level1.take(codes1), 10)
self.key2 = np.tile(level2.take(codes2), 10)
self.df = DataFrame({'data1': np.random.randn(100000),
'data2': np.random.randn(100000),
'key1': self.key1,
Expand Down
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class LevelAlign(object):
def setup(self):
self.index = MultiIndex(
levels=[np.arange(10), np.arange(100), np.arange(100)],
labels=[np.arange(10).repeat(10000),
np.tile(np.arange(100).repeat(100), 10),
np.tile(np.tile(np.arange(100), 100), 10)])
codes=[np.arange(10).repeat(10000),
np.tile(np.arange(100).repeat(100), 10),
np.tile(np.tile(np.arange(100), 100), 10)])
self.df = DataFrame(np.random.randn(len(self.index), 4),
index=self.index)
self.df_level = DataFrame(np.random.randn(100, 4),
Expand Down
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,8 @@ Deprecations
The functionality is unchanged. This new name better reflects the natures of
these codes and makes the API more similar to the API for
:class:`CategoricalIndex`(:issue:`13443`).
As a concequence, other uses of the name ``labels`` have also been deprecated in ``MultiIndex`` and replaced with ``codes``:
- You should initialize a MultiIndex instance using a parameter named ``codes`` rather than ``labels``.
As a consequence, other uses of the name ``labels`` have also been deprecated in ``MultiIndex`` and replaced with ``codes``:
- You should initialize a ``MultiIndex`` instance using a parameter named ``codes`` rather than ``labels``.
- :meth:`MultiIndex.set_labels` has been deprecated in favor of :meth:`MultiIndex.set_codes`
- for method :meth:`MultiIndex.copy`, the ``labels`` parameter has been deprecated and replaced by a ``codes`` parameter.
- :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`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3785,8 +3785,8 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
... ['speed', 'weight', 'length']],
... labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
>>> df = pd.DataFrame(index=midx, columns=['big', 'small'],
... data=[[45, 30], [200, 100], [1.5, 1], [30, 20],
... [250, 150], [1.5, 0.8], [320, 250],
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def codes(self):

@property
def labels(self):
warnings.warn(("labels was deprecated in version 0.24.0. "
warnings.warn((".labels was deprecated in version 0.24.0. "
"Use .codes instead."),
FutureWarning, stacklevel=2)
return self.codes
Expand Down Expand Up @@ -463,7 +463,7 @@ def _set_codes(self, codes, level=None, copy=False, validate=True,

def set_labels(self, labels, level=None, inplace=False,
verify_integrity=True):
warnings.warn(("set_labels was deprecated in version 0.24.0. "
warnings.warn((".set_labels was deprecated in version 0.24.0. "
"Use .set_codes instead."),
FutureWarning, stacklevel=2)
return self.set_codes(codes=labels, level=level, inplace=inplace,
Expand Down Expand Up @@ -1494,7 +1494,7 @@ def _sort_levels_monotonic(self):
--------
>>> i = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
>>> i
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
Expand Down Expand Up @@ -1869,7 +1869,7 @@ def swaplevel(self, i=-2, j=-1):
Examples
--------
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
... labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
... codes=[[0, 0, 1, 1], [0, 1, 0, 1]])
>>> mi
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3560,8 +3560,8 @@ def drop(self, labels=None, axis=0, index=None, columns=None,
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
... ['speed', 'weight', 'length']],
... labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
>>> s = pd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
... index=midx)
>>> s
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexes/multi/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_labels_deprecated(idx):
with tm.assert_produces_warning(FutureWarning):
idx.copy(labels=codes)


def test_view(idx):
i_view = idx.view()
assert_multiindex_copied(i_view, idx)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/multi/test_get_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_set_levels_codes_names_bad_input(idx):
with pytest.raises(ValueError, match='Length of levels'):
idx.set_levels([levels[0]])

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

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

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

# shouldn't scalar data error, instead should demand list-like
Expand Down
16 changes: 10 additions & 6 deletions pandas/tests/io/test_feather.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ def test_rw_nthreads(self):
"the 'nthreads' keyword is deprecated, "
"use 'use_threads' instead"
)
with tm.assert_produces_warning(FutureWarning) as w:
# TODO: make the warning work with check_stacklevel=True
with tm.assert_produces_warning(
FutureWarning, check_stacklevel=False) as w:
self.check_round_trip(df, nthreads=2)
assert len(w) == 1
assert expected_warning in str(w[0])
# we have an extra FutureWarning because of #GH23752
assert any(expected_warning in str(x) for x in w)

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

def test_rw_use_threads(self):
df = pd.DataFrame({'A': np.arange(100000)})
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,6 @@ def test_too_many_ndims(self):
with pytest.raises(TypeError, match=msg):
algos.rank(arr)

@pytest.mark.xfail(reason="MemoryError")
@pytest.mark.parametrize('values', [
np.arange(2**24 + 1),
np.arange(2**25 + 2).reshape(2**24 + 1, 2)],
Expand Down

0 comments on commit fc2c214

Please sign in to comment.