From 42b1c7d96748c91d2414419cd730706bd4298948 Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Thu, 14 Sep 2017 00:42:30 +0530 Subject: [PATCH 01/28] FIX for set_categories issue #17509 --- pandas/core/categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index dbd2a79b7e46d..fc2e2860e89b3 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -2068,7 +2068,7 @@ def _delegate_method(self, name, *args, **kwargs): method = getattr(self.categorical, name) res = method(*args, **kwargs) if res is not None: - return Series(res, index=self.index) + return Series(res, index=self.index, name=self.name) @classmethod def _make_accessor(cls, data): From 3843746dd4f6a24d931e0cc4a9289dd6b914c61a Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Thu, 14 Sep 2017 04:32:29 +0530 Subject: [PATCH 02/28] FIX for set_categories issue #17509 --- pandas/core/categorical.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index fc2e2860e89b3..5bd6e2df5945a 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -2047,9 +2047,10 @@ class CategoricalAccessor(PandasDelegate, NoNewAttributesMixin): """ - def __init__(self, values, index): + def __init__(self, name, values, index): self.categorical = values self.index = index + self.name = name self._freeze() def _delegate_property_get(self, name): @@ -2075,7 +2076,7 @@ def _make_accessor(cls, data): if not is_categorical_dtype(data.dtype): raise AttributeError("Can only use .cat accessor with a " "'category' dtype") - return CategoricalAccessor(data.values, data.index) + return CategoricalAccessor(data.values, data.index, data.name) CategoricalAccessor._add_delegate_accessors(delegate=Categorical, From 4f731cffcdd6ad0e302ac09603cd21526e627c88 Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Thu, 14 Sep 2017 04:36:08 +0530 Subject: [PATCH 03/28] FIX for set_categories issue #17509 --- pandas/core/categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index 5bd6e2df5945a..762163545630a 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -2076,7 +2076,7 @@ def _make_accessor(cls, data): if not is_categorical_dtype(data.dtype): raise AttributeError("Can only use .cat accessor with a " "'category' dtype") - return CategoricalAccessor(data.values, data.index, data.name) + return CategoricalAccessor(getattr(data, 'name', None), data.values, data.index) CategoricalAccessor._add_delegate_accessors(delegate=Categorical, From a4ba634e6548e1dfc163933b999f3f55611c97f6 Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Thu, 14 Sep 2017 04:39:05 +0530 Subject: [PATCH 04/28] Update categorical.py --- pandas/core/categorical.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index 762163545630a..029d89dd80fc8 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -2076,7 +2076,8 @@ def _make_accessor(cls, data): if not is_categorical_dtype(data.dtype): raise AttributeError("Can only use .cat accessor with a " "'category' dtype") - return CategoricalAccessor(getattr(data, 'name', None), data.values, data.index) + return CategoricalAccessor(getattr(data, 'name', None), + data.values, data.index) CategoricalAccessor._add_delegate_accessors(delegate=Categorical, From b817366a7ccd9cac01671cf9f2ede5ceb9b749c3 Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Thu, 14 Sep 2017 05:01:17 +0530 Subject: [PATCH 05/28] Update categorical.py --- pandas/core/categorical.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index 029d89dd80fc8..5710ca87093cc 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -2047,7 +2047,7 @@ class CategoricalAccessor(PandasDelegate, NoNewAttributesMixin): """ - def __init__(self, name, values, index): + def __init__(self, values, index, name): self.categorical = values self.index = index self.name = name @@ -2076,8 +2076,8 @@ def _make_accessor(cls, data): if not is_categorical_dtype(data.dtype): raise AttributeError("Can only use .cat accessor with a " "'category' dtype") - return CategoricalAccessor(getattr(data, 'name', None), - data.values, data.index) + return CategoricalAccessor(data.values, data.index, + getattr(data, 'name', None),) CategoricalAccessor._add_delegate_accessors(delegate=Categorical, From aa782ddecc0b243a738cc181cb0fa802b4f88eef Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Fri, 15 Sep 2017 21:05:58 +0530 Subject: [PATCH 06/28] Test for the changes --- pandas/tests/test_categorical.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 1fa3c84dc0260..8739533a80e01 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -57,6 +57,13 @@ def test_getitem_listlike(self): expected = c[np.array([100000]).astype(np.int64)].codes tm.assert_numpy_array_equal(result, expected) + def test_getname_category(self): + result = 'A' + s = pd.Series([1, 2, 3], name='A').astype('category') + s = s.cat.set_categories([1, 2, 3]) + expected = s.astype('category').name + tm.assert_almost_equal(result, expected) +  def test_getitem_category_type(self): # GH 14580 # test iloc() on Series with Categorical data From 4c30c9697c35d11f9f318616a0dbacfd0c2aeec1 Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Fri, 15 Sep 2017 22:50:01 +0530 Subject: [PATCH 07/28] Space removed --- pandas/tests/test_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 8739533a80e01..76ca87d3fdd7c 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -63,7 +63,7 @@ def test_getname_category(self): s = s.cat.set_categories([1, 2, 3]) expected = s.astype('category').name tm.assert_almost_equal(result, expected) -  + def test_getitem_category_type(self): # GH 14580 # test iloc() on Series with Categorical data From 42afe67479e47265a96a6b51f8435e1bc568a66b Mon Sep 17 00:00:00 2001 From: Giftlin <31629119+Giftlin@users.noreply.github.com> Date: Sat, 16 Sep 2017 02:02:58 +0530 Subject: [PATCH 08/28] =?UTF-8?q?-=C2=A0Bug=20in=20preserving=20name=20in?= =?UTF-8?q?=20set=5Fcategories.=20(:issue:`17509`)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/source/whatsnew/v0.21.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 52e056103cbdc..d9996845f856d 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,6 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) +- Bug in preserving name in ``set_categories``. (:issue:`17509`) PyPy ^^^^ From 8f888efed68d1112cf6fd1f34a971b87eec16871 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 17:48:51 +0530 Subject: [PATCH 09/28] Update v0.21.0.txt --- doc/source/whatsnew/v0.21.0.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index d9996845f856d..eacb51e793bec 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,8 +566,9 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in preserving name in ``set_categories``. (:issue:`17509`) - +- Bug in categorical operations on Series like `Series.cat.set_categories` + not preserving the original Series' name (:issue:`17509`) +  PyPy ^^^^ From f09c9d5dd54a1143b81d976bb34aaccaea420bbf Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 17:50:26 +0530 Subject: [PATCH 10/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 76ca87d3fdd7c..89e8ca00a459f 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -58,10 +58,10 @@ def test_getitem_listlike(self): tm.assert_numpy_array_equal(result, expected) def test_getname_category(self): - result = 'A' + expected = 'A' s = pd.Series([1, 2, 3], name='A').astype('category') s = s.cat.set_categories([1, 2, 3]) - expected = s.astype('category').name + result = s.astype('category').name tm.assert_almost_equal(result, expected) def test_getitem_category_type(self): From 8781d64db4e38b63af3591e56fe829375b18a59a Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 18:25:46 +0530 Subject: [PATCH 11/28] Update v0.21.0.txt --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index eacb51e793bec..ef482102a834c 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,7 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations on Series like `Series.cat.set_categories` +- Bug in categorical operations on Series like ``Series.cat.set_categories`` not preserving the original Series' name (:issue:`17509`)   PyPy From 2ed3740b5e4b97862ec544f015b82b012be4dbe0 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 18:28:26 +0530 Subject: [PATCH 12/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 89e8ca00a459f..546126d77e4eb 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -60,8 +60,7 @@ def test_getitem_listlike(self): def test_getname_category(self): expected = 'A' s = pd.Series([1, 2, 3], name='A').astype('category') - s = s.cat.set_categories([1, 2, 3]) - result = s.astype('category').name + result = s.cat.set_categories([1, 2, 3]).name tm.assert_almost_equal(result, expected) def test_getitem_category_type(self): From 8192515fdb40b658486c0a2f5e04570072452931 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 18:52:31 +0530 Subject: [PATCH 13/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 546126d77e4eb..7868d52171712 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -58,11 +58,48 @@ def test_getitem_listlike(self): tm.assert_numpy_array_equal(result, expected) def test_getname_category(self): - expected = 'A' + s = pd.Series([1, 2, 3], name='A').astype('category') + # 'set_categories' + expected = 'A' result = s.cat.set_categories([1, 2, 3]).name tm.assert_almost_equal(result, expected) + # 'reorder_categories' + expected = 'A' + result = s.cat.reorder_categories([2, 3, 1], ordered=True).name + tm.assert_almost_equal(result, expected) + + # 'rename_categories' + expected = 'A' + result = s.cat.rename_categories([1,2,3]).name + tm.assert_almost_equal(result, expected) + + # 'remove_unused_categories' + expected = 'A' + result = s.cat.remove_unused_categories().name + tm.assert_almost_equal(result, expected) + + # 'remove_categories' + expected = 'A' + result = s.cat.remove_categories([2]).name + tm.assert_almost_equal(result, expected) + + # 'add_categories' + expected = 'A' + result = s.cat.add_categories([4]).name + tm.assert_almost_equal(result, expected) + + # 'as_ordered' + expected = 'A' + result = s.cat.as_ordered().name + tm.assert_almost_equal(result, expected) + + # 'as_ordered' + expected = 'A' + result = s.cat.as_ordered().name + tm.assert_almost_equal(result, expected) + def test_getitem_category_type(self): # GH 14580 # test iloc() on Series with Categorical data From 9007df3e7c7e7589fa75b0fd01f5e27dcd9b25bd Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 20:12:24 +0530 Subject: [PATCH 14/28] Update v0.21.0.txt --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index ef482102a834c..86b431ec7e429 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,7 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations on Series like ``Series.cat.set_categories`` +- Bug in categorical operations `Series.cat ' on Series like ``Series.cat.set_categories`` not preserving the original Series' name (:issue:`17509`)   PyPy From 72c9ebe9f78aaf9a9549d696a88d20d9c70b6ab5 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 20:18:52 +0530 Subject: [PATCH 15/28] Update v0.21.0.txt --- doc/source/whatsnew/v0.21.0.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 86b431ec7e429..8b1c69c3d389d 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,8 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations `Series.cat ' on Series like ``Series.cat.set_categories`` - not preserving the original Series' name (:issue:`17509`) +- Bug in categorical operations `Series.cat ' not preserving the original Series' name (:issue:`17509`)   PyPy ^^^^ From 90ff725f3eb08669ea2aef93e45b91172ae0fabc Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 21:04:29 +0530 Subject: [PATCH 16/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 53 +++++++++----------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 7868d52171712..5aa13f9f26767 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -57,48 +57,23 @@ def test_getitem_listlike(self): expected = c[np.array([100000]).astype(np.int64)].codes tm.assert_numpy_array_equal(result, expected) - def test_getname_category(self): - + @pytest.mark.parametrize("method", + [ + lambda x: x.cat.set_categories([1, 2, 3]), + lambda x: x.cat.reorder_categories([2, 3, 1], ordered=True), + lambda x: x.cat.rename_categories([1,2,3]), + lambda x: x.cat.remove_unused_categories(), + lambda x: x.cat.remove_categories([2]), + lambda x: x.cat.add_categories([4]), + lambda x: x.cat.as_ordered(), + lambda x: x.cat.as_unordered(), + ]) + def test_getname_categorical_accessor(self, method): s = pd.Series([1, 2, 3], name='A').astype('category') - # 'set_categories' - expected = 'A' - result = s.cat.set_categories([1, 2, 3]).name - tm.assert_almost_equal(result, expected) - - # 'reorder_categories' - expected = 'A' - result = s.cat.reorder_categories([2, 3, 1], ordered=True).name - tm.assert_almost_equal(result, expected) - - # 'rename_categories' - expected = 'A' - result = s.cat.rename_categories([1,2,3]).name - tm.assert_almost_equal(result, expected) - - # 'remove_unused_categories' expected = 'A' - result = s.cat.remove_unused_categories().name - tm.assert_almost_equal(result, expected) - - # 'remove_categories' - expected = 'A' - result = s.cat.remove_categories([2]).name - tm.assert_almost_equal(result, expected) - - # 'add_categories' - expected = 'A' - result = s.cat.add_categories([4]).name - tm.assert_almost_equal(result, expected) - - # 'as_ordered' - expected = 'A' - result = s.cat.as_ordered().name - tm.assert_almost_equal(result, expected) + result = method(s).name + assert result == expected - # 'as_ordered' - expected = 'A' - result = s.cat.as_ordered().name - tm.assert_almost_equal(result, expected) def test_getitem_category_type(self): # GH 14580 From f44a09ad0c845efc09e8f418ddad38c9ad94eba3 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Sun, 17 Sep 2017 23:20:59 +0530 Subject: [PATCH 17/28] Update v0.21.0.txt --- doc/source/whatsnew/v0.21.0.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 8b1c69c3d389d..49002cc19c11f 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,8 +566,8 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations `Series.cat ' not preserving the original Series' name (:issue:`17509`) -  +- Bug in categorical operations `Series.cat ' not preserving the original Series' name (:issue:`17509`) + PyPy ^^^^ From 3b40433c4786dcd1a347fae8bdb54e2ae2dd2336 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 00:28:32 +0530 Subject: [PATCH 18/28] Lint error fix --- pandas/tests/test_categorical.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 5aa13f9f26767..cc88aa9785813 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -59,22 +59,22 @@ def test_getitem_listlike(self): @pytest.mark.parametrize("method", [ - lambda x: x.cat.set_categories([1, 2, 3]), - lambda x: x.cat.reorder_categories([2, 3, 1], ordered=True), - lambda x: x.cat.rename_categories([1,2,3]), - lambda x: x.cat.remove_unused_categories(), - lambda x: x.cat.remove_categories([2]), - lambda x: x.cat.add_categories([4]), - lambda x: x.cat.as_ordered(), - lambda x: x.cat.as_unordered(), + lambda x: x.cat.set_categories([1, 2, 3]), + lambda x: x.cat.reorder_categories([2, 3, 1] + , ordered=True), + lambda x: x.cat.rename_categories([1,2, 3]), + lambda x: x.cat.remove_unused_categories(), + lambda x: x.cat.remove_categories([2]), + lambda x: x.cat.add_categories([4]), + lambda x: x.cat.as_ordered(), + lambda x: x.cat.as_unordered(), ]) def test_getname_categorical_accessor(self, method): s = pd.Series([1, 2, 3], name='A').astype('category') expected = 'A' result = method(s).name assert result == expected - - +  def test_getitem_category_type(self): # GH 14580 # test iloc() on Series with Categorical data From e21fe0877c1dd71ba733683f39e7e05b03eafa3b Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 00:41:41 +0530 Subject: [PATCH 19/28] Removed space Sorry for too many commits. --- pandas/tests/test_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index cc88aa9785813..a688d34d4a338 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -74,7 +74,7 @@ def test_getname_categorical_accessor(self, method): expected = 'A' result = method(s).name assert result == expected -  + def test_getitem_category_type(self): # GH 14580 # test iloc() on Series with Categorical data From 9730757a4443caab0cecd7bda93a65228aae2b58 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 01:01:15 +0530 Subject: [PATCH 20/28] Lint error --- pandas/tests/test_categorical.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index a688d34d4a338..5aeab5cf4ac89 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -59,15 +59,15 @@ def test_getitem_listlike(self): @pytest.mark.parametrize("method", [ - lambda x: x.cat.set_categories([1, 2, 3]), + lambda x: x.cat.set_categories([1, 2, 3]), lambda x: x.cat.reorder_categories([2, 3, 1] - , ordered=True), - lambda x: x.cat.rename_categories([1,2, 3]), - lambda x: x.cat.remove_unused_categories(), - lambda x: x.cat.remove_categories([2]), - lambda x: x.cat.add_categories([4]), - lambda x: x.cat.as_ordered(), - lambda x: x.cat.as_unordered(), + ,ordered=True), + lambda x: x.cat.rename_categories([1, 2, 3]), + lambda x: x.cat.remove_unused_categories(), + lambda x: x.cat.remove_categories([2]), + lambda x: x.cat.add_categories([4]), + lambda x: x.cat.as_ordered(), + lambda x: x.cat.as_unordered(), ]) def test_getname_categorical_accessor(self, method): s = pd.Series([1, 2, 3], name='A').astype('category') From 5ae2453226613256d7c85846c0d0b9dcd2462bfb Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 07:23:13 +0530 Subject: [PATCH 21/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 5aeab5cf4ac89..7ba1acf1b2865 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -56,19 +56,19 @@ def test_getitem_listlike(self): result = c.codes[np.array([100000]).astype(np.int64)] expected = c[np.array([100000]).astype(np.int64)].codes tm.assert_numpy_array_equal(result, expected) - - @pytest.mark.parametrize("method", - [ - lambda x: x.cat.set_categories([1, 2, 3]), - lambda x: x.cat.reorder_categories([2, 3, 1] - ,ordered=True), - lambda x: x.cat.rename_categories([1, 2, 3]), - lambda x: x.cat.remove_unused_categories(), - lambda x: x.cat.remove_categories([2]), - lambda x: x.cat.add_categories([4]), - lambda x: x.cat.as_ordered(), - lambda x: x.cat.as_unordered(), - ]) +  + @pytest.mark.parametrize( + method", + [ + lambda x: x.cat.set_categories([1, 2, 3]), + lambda x: x.cat.reorder_categories([2, 3, 1], ordered=True), + lambda x: x.cat.rename_categories([1, 2, 3]), + lambda x: x.cat.remove_unused_categories(), + lambda x: x.cat.remove_categories([2]), + lambda x: x.cat.add_categories([4]), + lambda x: x.cat.as_ordered(), + lambda x: x.cat.as_unordered(), + ]) def test_getname_categorical_accessor(self, method): s = pd.Series([1, 2, 3], name='A').astype('category') expected = 'A' From 9f25ad995749a7f1f2bbece8869fa5164c3483f6 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 07:24:09 +0530 Subject: [PATCH 22/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 7ba1acf1b2865..e031616e63bb2 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -58,7 +58,7 @@ def test_getitem_listlike(self): tm.assert_numpy_array_equal(result, expected)   @pytest.mark.parametrize( - method", + "method", [ lambda x: x.cat.set_categories([1, 2, 3]), lambda x: x.cat.reorder_categories([2, 3, 1], ordered=True), From 6b4f0f234e056b6c1d3ff400ecde004be4f05f5d Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 08:23:33 +0530 Subject: [PATCH 23/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index e031616e63bb2..91d98251f35ae 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -56,7 +56,7 @@ def test_getitem_listlike(self): result = c.codes[np.array([100000]).astype(np.int64)] expected = c[np.array([100000]).astype(np.int64)].codes tm.assert_numpy_array_equal(result, expected) -  + @pytest.mark.parametrize( "method", [ From 68a2d86c5c8f8e0d771b54be4806ab23e377c20a Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 12:54:57 +0530 Subject: [PATCH 24/28] Update v0.21.0.txt http://pandas.pydata.org/pandas-docs/stable/categorical.html#working-with-categories --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 49002cc19c11f..a9bf3c2257028 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,7 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations `Series.cat ' not preserving the original Series' name (:issue:`17509`) +- Bug in categorical operations `Series.cat ' not preserving the original Series' name (:issue:`17509`) PyPy ^^^^ From a94d52a3d104ad1c02620e6f074ee5136a02e6fb Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 13:12:15 +0530 Subject: [PATCH 25/28] Update v0.21.0.txt --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index a9bf3c2257028..e63ec687fe830 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,7 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations `Series.cat ' not preserving the original Series' name (:issue:`17509`) +- Bug in categorical operations :ref:`Series.cat ' not preserving the original Series' name (:issue:`17509`) PyPy ^^^^ From 73f5241190d4fe7049e6cccee5e0eaad0891d055 Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 13:23:22 +0530 Subject: [PATCH 26/28] Update categorical.rst --- doc/source/categorical.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/categorical.rst b/doc/source/categorical.rst index 8835c4a1533d0..acc16b05d0913 100644 --- a/doc/source/categorical.rst +++ b/doc/source/categorical.rst @@ -3,7 +3,7 @@ .. currentmodule:: pandas .. ipython:: python - :suppress: +   :suppress: import numpy as np import pandas as pd @@ -144,8 +144,9 @@ Using ``.describe()`` on categorical data will produce similar output to a `Seri cat = pd.Categorical(["a", "c", "c", np.nan], categories=["b", "a", "c"]) df = pd.DataFrame({"cat":cat, "s":["a", "c", "c", np.nan]}) df.describe() - df["cat"].describe() +    df["cat"].describe() +.. _categorical.cat: Working with categories ----------------------- From 7bb33789cea46dd03d40ec9992b453b6b297e53e Mon Sep 17 00:00:00 2001 From: Giftlin Rajaiah Date: Mon, 18 Sep 2017 13:50:20 +0530 Subject: [PATCH 27/28] Update test_categorical.py --- pandas/tests/test_categorical.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index 91d98251f35ae..afea2815600ab 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -70,6 +70,7 @@ def test_getitem_listlike(self): lambda x: x.cat.as_unordered(), ]) def test_getname_categorical_accessor(self, method): + # https://github.com/pandas-dev/pandas/issues/17509 s = pd.Series([1, 2, 3], name='A').astype('category') expected = 'A' result = method(s).name From ce78e6c98b6f5dd18bfaaf111cbd921ebf37cfc3 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 18 Sep 2017 13:36:01 +0200 Subject: [PATCH 28/28] small edits --- doc/source/categorical.rst | 5 +++-- doc/source/whatsnew/v0.21.0.txt | 2 +- pandas/tests/test_categorical.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/categorical.rst b/doc/source/categorical.rst index acc16b05d0913..65361886436d6 100644 --- a/doc/source/categorical.rst +++ b/doc/source/categorical.rst @@ -3,7 +3,7 @@ .. currentmodule:: pandas .. ipython:: python -   :suppress: + :suppress: import numpy as np import pandas as pd @@ -144,9 +144,10 @@ Using ``.describe()`` on categorical data will produce similar output to a `Seri cat = pd.Categorical(["a", "c", "c", np.nan], categories=["b", "a", "c"]) df = pd.DataFrame({"cat":cat, "s":["a", "c", "c", np.nan]}) df.describe() -    df["cat"].describe() + df["cat"].describe() .. _categorical.cat: + Working with categories ----------------------- diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index e63ec687fe830..d192166f620f2 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -566,7 +566,7 @@ Categorical - Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`) -- Bug in categorical operations :ref:`Series.cat ' not preserving the original Series' name (:issue:`17509`) +- Bug in categorical operations with :ref:`Series.cat ' not preserving the original Series' name (:issue:`17509`) PyPy ^^^^ diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index afea2815600ab..c361b430cfd8a 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -70,7 +70,7 @@ def test_getitem_listlike(self): lambda x: x.cat.as_unordered(), ]) def test_getname_categorical_accessor(self, method): - # https://github.com/pandas-dev/pandas/issues/17509 + # GH 17509 s = pd.Series([1, 2, 3], name='A').astype('category') expected = 'A' result = method(s).name