From 867c24cfe4fedb00e06bf7b240486c06a1cc6535 Mon Sep 17 00:00:00 2001 From: tp Date: Sun, 18 Nov 2018 10:24:56 +0000 Subject: [PATCH] update PR --- asv_bench/benchmarks/groupby.py | 4 ++-- asv_bench/benchmarks/join_merge.py | 6 +++--- asv_bench/benchmarks/reindex.py | 6 +++--- doc/source/whatsnew/v0.24.0.rst | 4 ++-- pandas/core/frame.py | 4 ++-- pandas/core/indexes/multi.py | 8 ++++---- pandas/core/series.py | 4 ++-- pandas/tests/indexes/multi/test_get_set.py | 4 ++-- pandas/tests/io/test_feather.py | 16 ++++++++++------ pandas/tests/test_algos.py | 1 - 10 files changed, 30 insertions(+), 27 deletions(-) diff --git a/asv_bench/benchmarks/groupby.py b/asv_bench/benchmarks/groupby.py index dbd79185ec006e..9d19525fd30db0 100644 --- a/asv_bench/benchmarks/groupby.py +++ b/asv_bench/benchmarks/groupby.py @@ -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 diff --git a/asv_bench/benchmarks/join_merge.py b/asv_bench/benchmarks/join_merge.py index 5b28d8a4eec623..837af192b965d9 100644 --- a/asv_bench/benchmarks/join_merge.py +++ b/asv_bench/benchmarks/join_merge.py @@ -119,10 +119,10 @@ 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']) diff --git a/asv_bench/benchmarks/reindex.py b/asv_bench/benchmarks/reindex.py index 82c61a98e2c343..576dc495eb9847 100644 --- a/asv_bench/benchmarks/reindex.py +++ b/asv_bench/benchmarks/reindex.py @@ -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), diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index c7cbf726f9a57e..aa86c62ae79bd9 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -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`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 70be16702d123e..c0ffa131f737cd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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], diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 519eca69a7bac6..6323889073924f 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -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 @@ -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, @@ -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]]) @@ -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]]) diff --git a/pandas/core/series.py b/pandas/core/series.py index dec869ff490269..f47888fcf78ef0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 diff --git a/pandas/tests/indexes/multi/test_get_set.py b/pandas/tests/indexes/multi/test_get_set.py index 5b43c9050e9208..d201cb2eb178bd 100644 --- a/pandas/tests/indexes/multi/test_get_set.py +++ b/pandas/tests/indexes/multi/test_get_set.py @@ -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'): @@ -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 diff --git a/pandas/tests/io/test_feather.py b/pandas/tests/io/test_feather.py index 16b59526c8233b..b070aa909cc94a 100644 --- a/pandas/tests/io/test_feather.py +++ b/pandas/tests/io/test_feather.py @@ -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)}) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 286fb7fa07e6a1..ff505f2986b1a6 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -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)],