From 6afcbcd9b8915b0bef770d2bab77d6285d9a459d Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 18 Apr 2021 20:02:45 +0200 Subject: [PATCH 01/23] check for string and convert to list --- pandas/core/frame.py | 3 +++ pandas/tests/frame/methods/test_dropna.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 38766d2856cfe..0392a6f45ad1a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5919,6 +5919,9 @@ def dropna( agg_obj = self if subset is not None: + if isinstance(subset, str): + # subset needs to be list like + subset = [subset] ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) check = indices == -1 diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index b671bb1afb27a..8969f7db5e423 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -231,3 +231,11 @@ def test_dropna_with_duplicate_columns(self): result = df.dropna(subset=["A", "C"], how="all") tm.assert_frame_equal(result, expected) + + def test_set_single_column_subset(self): + df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) + expected = DataFrame( + {"A": [1, 3], "B": list("ac"), "C": [4.0, 5.0]}, index=[0, 2] + ) + result = df.dropna(subset="C") + tm.assert_frame_equal(result, expected) From 86d2cd868d8486dbab7fd8fceac81bce56d03487 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 18 Apr 2021 21:58:06 +0200 Subject: [PATCH 02/23] add test for missing key in axis --- pandas/tests/frame/methods/test_dropna.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 8969f7db5e423..c75bb6f3fae0c 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -233,9 +233,21 @@ def test_dropna_with_duplicate_columns(self): tm.assert_frame_equal(result, expected) def test_set_single_column_subset(self): + # GH 41021 df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) expected = DataFrame( {"A": [1, 3], "B": list("ac"), "C": [4.0, 5.0]}, index=[0, 2] ) result = df.dropna(subset="C") tm.assert_frame_equal(result, expected) + + def test_single_column_not_present_in_axis(self): + # GH 41021 + """ + Test if KeyError is raised when subset is not present in axis + """ + df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) + + # Column not present + with pytest.raises(KeyError): + df.dropna(subset="D", axis=0) From 03d3e0dbc497059db035bb1ac65433a276bdbc83 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 18 Apr 2021 22:07:15 +0200 Subject: [PATCH 03/23] add match pytest --- pandas/tests/frame/methods/test_dropna.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index c75bb6f3fae0c..ffcffe9a15e71 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -249,5 +249,5 @@ def test_single_column_not_present_in_axis(self): df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) # Column not present - with pytest.raises(KeyError): + with pytest.raises(KeyError, match="Given column does not exist"): df.dropna(subset="D", axis=0) From f7a1847c8ba93f941e8a632901577825eee77906 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 18 Apr 2021 22:10:02 +0200 Subject: [PATCH 04/23] add whatsnew entry --- doc/source/whatsnew/v1.2.5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.5.rst b/doc/source/whatsnew/v1.2.5.rst index 16f9284802407..d6e644a6cb898 100644 --- a/doc/source/whatsnew/v1.2.5.rst +++ b/doc/source/whatsnew/v1.2.5.rst @@ -35,7 +35,7 @@ Bug fixes Other ~~~~~ -- +- :meth:`DataFrame.sum` now accepts a single column / string as ``subset`` instead of array-like - .. --------------------------------------------------------------------------- From 0326c7a5514f768ff900b5ba175451c11b0ccc4f Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 18 Apr 2021 22:18:30 +0200 Subject: [PATCH 05/23] add correct typing and checks --- pandas/core/frame.py | 13 ++++++++++--- pandas/tests/frame/methods/test_dropna.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0392a6f45ad1a..3b2bc20605005 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -27,7 +27,9 @@ Hashable, Iterable, Iterator, + Optional, Sequence, + Union, cast, overload, ) @@ -5803,7 +5805,7 @@ def dropna( axis: Axis = 0, how: str = "any", thresh=None, - subset=None, + subset: Optional[Union[Hashable, Sequence[Hashable]]] = None, inplace: bool = False, ): """ @@ -5919,9 +5921,14 @@ def dropna( agg_obj = self if subset is not None: - if isinstance(subset, str): + if ( + not np.iterable(subset) + or isinstance(subset, str) + or isinstance(subset, tuple) + and subset in self.columns + ): # subset needs to be list like - subset = [subset] + subset = (subset,) ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) check = indices == -1 diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index ffcffe9a15e71..1acf2ef3221b5 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -249,5 +249,5 @@ def test_single_column_not_present_in_axis(self): df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) # Column not present - with pytest.raises(KeyError, match="Given column does not exist"): + with pytest.raises(KeyError, match="['D']"): df.dropna(subset="D", axis=0) From 63a78ef3bae30182bb5e2b195f705dd3ba97739c Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 18 Apr 2021 22:20:04 +0200 Subject: [PATCH 06/23] rename typing in docstring: --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3b2bc20605005..de74fe9c37b80 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5837,7 +5837,7 @@ def dropna( thresh : int, optional Require that many non-NA values. - subset : array-like, optional + subset : column label or sequence of labels, optional Labels along other axis to consider, e.g. if you are dropping rows these would be a list of columns to include. inplace : bool, default False From 93fb0b315fbaa194c5ca396f20f2da2a44667b30 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 19 Apr 2021 01:12:47 +0200 Subject: [PATCH 07/23] fix typo whatsnew --- doc/source/whatsnew/v1.2.5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.5.rst b/doc/source/whatsnew/v1.2.5.rst index d6e644a6cb898..f81a136345310 100644 --- a/doc/source/whatsnew/v1.2.5.rst +++ b/doc/source/whatsnew/v1.2.5.rst @@ -35,7 +35,7 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.sum` now accepts a single column / string as ``subset`` instead of array-like +- :meth:`DataFrame.dropna` now accepts a single column / string as ``subset`` instead of array-like - .. --------------------------------------------------------------------------- From 103bd357b02cbeeeff8c357b2503525321773605 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 19 Apr 2021 01:16:58 +0200 Subject: [PATCH 08/23] use is list like --- pandas/core/frame.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index de74fe9c37b80..6e288a86f9e28 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5921,12 +5921,7 @@ def dropna( agg_obj = self if subset is not None: - if ( - not np.iterable(subset) - or isinstance(subset, str) - or isinstance(subset, tuple) - and subset in self.columns - ): + if not is_list_like(subset): # subset needs to be list like subset = (subset,) ax = self._get_axis(agg_axis) From 365c6c01ee9e48598cf425039497134a4e50e261 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 19 Apr 2021 01:17:06 +0200 Subject: [PATCH 09/23] fix tests --- pandas/tests/frame/methods/test_dropna.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 1acf2ef3221b5..053a54a7b58e9 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -243,10 +243,7 @@ def test_set_single_column_subset(self): def test_single_column_not_present_in_axis(self): # GH 41021 - """ - Test if KeyError is raised when subset is not present in axis - """ - df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) + df = DataFrame({"A": [1, 2, 3]}) # Column not present with pytest.raises(KeyError, match="['D']"): From cace36997b091e3d5cb69ec2f4f865d0be10ee20 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 19 Apr 2021 14:21:16 +0200 Subject: [PATCH 10/23] fix typing --- pandas/core/frame.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6e288a86f9e28..8147a2f557adf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -27,9 +27,7 @@ Hashable, Iterable, Iterator, - Optional, Sequence, - Union, cast, overload, ) @@ -5805,7 +5803,7 @@ def dropna( axis: Axis = 0, how: str = "any", thresh=None, - subset: Optional[Union[Hashable, Sequence[Hashable]]] = None, + subset: Hashable | Sequence[Hashable] | None = None, inplace: bool = False, ): """ From 66d447d335073b9a50fd436032bfc06ecc626432 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 19 Apr 2021 14:25:42 +0200 Subject: [PATCH 11/23] use pandas typing --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8147a2f557adf..e3da4ca443381 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5803,7 +5803,7 @@ def dropna( axis: Axis = 0, how: str = "any", thresh=None, - subset: Hashable | Sequence[Hashable] | None = None, + subset: IndexLabel = None, inplace: bool = False, ): """ From 7be5fe73afd9b55c3fbcfe148d42f99259197222 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 20 Apr 2021 09:56:31 +0200 Subject: [PATCH 12/23] more clear whatsnew entry --- doc/source/whatsnew/v1.2.5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.5.rst b/doc/source/whatsnew/v1.2.5.rst index f81a136345310..4189833484034 100644 --- a/doc/source/whatsnew/v1.2.5.rst +++ b/doc/source/whatsnew/v1.2.5.rst @@ -35,7 +35,7 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.dropna` now accepts a single column / string as ``subset`` instead of array-like +- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with of array-like. - .. --------------------------------------------------------------------------- From 1dd0a647411297ca68b7ee24fafa7f7a2972b3a0 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 20 Apr 2021 11:29:53 +0200 Subject: [PATCH 13/23] move whatsnew entry to 1.3 --- doc/source/whatsnew/v1.2.5.rst | 1 - doc/source/whatsnew/v1.3.0.rst | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.2.5.rst b/doc/source/whatsnew/v1.2.5.rst index 4189833484034..2fc1a7b23a022 100644 --- a/doc/source/whatsnew/v1.2.5.rst +++ b/doc/source/whatsnew/v1.2.5.rst @@ -35,7 +35,6 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with of array-like. - .. --------------------------------------------------------------------------- diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 85d9acff353be..b8ddb81977a43 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -219,7 +219,7 @@ Other enhancements - :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`) - :meth:`.GroupBy.any` and :meth:`.GroupBy.all` use Kleene logic with nullable data types (:issue:`37506`) - :meth:`.GroupBy.any` and :meth:`.GroupBy.all` return a ``BooleanDtype`` for columns with nullable data types (:issue:`33449`) -- +- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like. .. --------------------------------------------------------------------------- From 56ef81edb1dbba2d29ab0393bef945ddf7e77c20 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Tue, 20 Apr 2021 12:35:49 +0200 Subject: [PATCH 14/23] revert whatsnew 1.2.5 to master --- doc/source/whatsnew/v1.2.5.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.2.5.rst b/doc/source/whatsnew/v1.2.5.rst index 2fc1a7b23a022..16f9284802407 100644 --- a/doc/source/whatsnew/v1.2.5.rst +++ b/doc/source/whatsnew/v1.2.5.rst @@ -35,6 +35,7 @@ Bug fixes Other ~~~~~ +- - .. --------------------------------------------------------------------------- From 4b905e5da29f372d3351854a907e70c4e648f7b7 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 12:04:14 +0200 Subject: [PATCH 15/23] use com.maybe_make_list --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fa6c3e2976247..18d898d24ad83 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5992,7 +5992,7 @@ def dropna( if subset is not None: if not is_list_like(subset): # subset needs to be list like - subset = (subset,) + subset = com.maybe_make_list(subset) ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) check = indices == -1 From c585c8f82e20c9b90ac4d02ba89dbe34807278eb Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 13:15:04 +0200 Subject: [PATCH 16/23] remove is list like --- pandas/core/frame.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 18d898d24ad83..18575de86fcc3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5990,9 +5990,8 @@ def dropna( agg_obj = self if subset is not None: - if not is_list_like(subset): - # subset needs to be list like - subset = com.maybe_make_list(subset) + # subset needs to be lst + subset = com.maybe_make_list(subset) ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) check = indices == -1 From 1d5f208bfc585de32b0914b114364b9281cb8c6a Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 13:21:39 +0200 Subject: [PATCH 17/23] remove list like --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 18575de86fcc3..b244957d2f642 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5990,7 +5990,7 @@ def dropna( agg_obj = self if subset is not None: - # subset needs to be lst + # subset needs to be list subset = com.maybe_make_list(subset) ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) From 2bf5ac37a6e475e73bc4038481a006a42d761a51 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 16:17:36 +0200 Subject: [PATCH 18/23] move whatsnew entry to 1.4 --- doc/source/whatsnew/v1.3.4.rst | 1 - doc/source/whatsnew/v1.4.0.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.4.rst b/doc/source/whatsnew/v1.3.4.rst index 6595af6b08e91..d15354109fb3f 100644 --- a/doc/source/whatsnew/v1.3.4.rst +++ b/doc/source/whatsnew/v1.3.4.rst @@ -42,7 +42,6 @@ Bug fixes Other ~~~~~ -- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like. (:issue:`41021`) - .. --------------------------------------------------------------------------- diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index e638a24f830ef..c5b9ef8249ca5 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -129,6 +129,7 @@ Other enhancements - :meth:`DataFrame.__pos__`, :meth:`DataFrame.__neg__` now retain ``ExtensionDtype`` dtypes (:issue:`43883`) - The error raised when an optional dependency can't be imported now includes the original exception, for easier investigation (:issue:`43882`) - Added :meth:`.ExponentialMovingWindow.sum` (:issue:`13297`) +- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like. (:issue:`41021`) .. --------------------------------------------------------------------------- From 9ea97ff815fc15cde49325aa4131cd28b1326d16 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 16:17:52 +0200 Subject: [PATCH 19/23] revert to is_list_like and add test with np.array --- pandas/core/frame.py | 3 ++- pandas/tests/frame/methods/test_dropna.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b244957d2f642..093b45e44d13d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5991,7 +5991,8 @@ def dropna( agg_obj = self if subset is not None: # subset needs to be list - subset = com.maybe_make_list(subset) + if not is_list_like(subset): + subset = (subset,) ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) check = indices == -1 diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 0108d6983eb63..5ac9680bda306 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -260,3 +260,11 @@ def test_single_column_not_present_in_axis(self): # Column not present with pytest.raises(KeyError, match="['D']"): df.dropna(subset="D", axis=0) + + def test_subset_is_nparray(self): + # GH 41021 + df = DataFrame({"A": [1, 2, np.NaN], "B": list("abc"), "C": [4, np.NaN, 5]}) + expected = DataFrame({"A": [1.0], "B": ["a"], "C": [4.0]}) + result = df.dropna(subset=np.array(["A", "C"])) + tm.assert_frame_equal(result, expected) + From d09c6ba9bb293ef4640003706688c29cf750eabd Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 16:19:25 +0200 Subject: [PATCH 20/23] remove blank line --- pandas/tests/frame/methods/test_dropna.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 5ac9680bda306..1207c2763db07 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -267,4 +267,3 @@ def test_subset_is_nparray(self): expected = DataFrame({"A": [1.0], "B": ["a"], "C": [4.0]}) result = df.dropna(subset=np.array(["A", "C"])) tm.assert_frame_equal(result, expected) - From c09d147d3c1e1e4eae5894060297c3a2db54d776 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sun, 10 Oct 2021 19:57:57 +0200 Subject: [PATCH 21/23] use basic indexing instead of np.compress --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 093b45e44d13d..5a715492b07fe 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5997,7 +5997,7 @@ def dropna( indices = ax.get_indexer_for(subset) check = indices == -1 if check.any(): - raise KeyError(list(np.compress(check, subset))) + raise KeyError(np.array(subset)[check].tolist()) agg_obj = self.take(indices, axis=agg_axis) count = agg_obj.count(axis=agg_axis) From df5ca75bd51a56a545bad049dd85602e6e1c17b7 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 16 Oct 2021 19:25:37 +0200 Subject: [PATCH 22/23] remove dot --- doc/source/whatsnew/v1.4.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 6e60748366350..9e800995ad871 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -177,7 +177,7 @@ Other enhancements - :meth:`DataFrame.__pos__`, :meth:`DataFrame.__neg__` now retain ``ExtensionDtype`` dtypes (:issue:`43883`) - The error raised when an optional dependency can't be imported now includes the original exception, for easier investigation (:issue:`43882`) - Added :meth:`.ExponentialMovingWindow.sum` (:issue:`13297`) -- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like. (:issue:`41021`) +- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like (:issue:`41021`) - .. --------------------------------------------------------------------------- From 17fe9bcb8dd83f8e86ad78f8263e7e88fa9a5e71 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Sat, 16 Oct 2021 19:33:42 +0200 Subject: [PATCH 23/23] use list instead of tuple --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 960646771ad13..fd491559d7a10 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6046,7 +6046,7 @@ def dropna( if subset is not None: # subset needs to be list if not is_list_like(subset): - subset = (subset,) + subset = [subset] ax = self._get_axis(agg_axis) indices = ax.get_indexer_for(subset) check = indices == -1