From de6466384f5aa324bc097656f7f35ddc18fadcbb Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 12:47:43 +0200 Subject: [PATCH 01/23] [IMP] - #34932 - added option to ignore_index in DataFrame.explod --- pandas/core/frame.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b522920ec9f23..4ff0def44873f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6896,7 +6896,7 @@ def stack(self, level=-1, dropna=True): else: return stack(self, level, dropna=dropna) - def explode(self, column: Union[str, Tuple]) -> "DataFrame": + def explode(self, column: Union[str, Tuple], ignore_index=False) -> "DataFrame": """ Transform each element of a list-like to a row, replicating index values. @@ -6961,8 +6961,11 @@ def explode(self, column: Union[str, Tuple]) -> "DataFrame": # TODO: use overload to refine return type of reset_index assert df is not None # needed for mypy result = df[column].explode() - result = df.drop([column], axis=1).join(result) - result.index = self.index.take(result.index) + if ignore_index: + result = df.drop([column], axis=1).join(result).reset_index(drop=True) + else: + result = df.drop([column], axis=1).join(result) + result.index = self.index.take(result.index) result = result.reindex(columns=self.columns, copy=False) return result From 136a568188d2b65f022dadbc4a5bacd54a25c51a Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 15:26:38 +0200 Subject: [PATCH 02/23] ENH - #34932 - added docstring ignore_index to explode --- pandas/core/frame.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4ff0def44873f..22964d1977244 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6906,6 +6906,9 @@ def explode(self, column: Union[str, Tuple], ignore_index=False) -> "DataFrame": ---------- column : str or tuple Column to explode. + ignore_index : bool, default False + If True, the resulting index will be labeled 0, 1, …, n - 1. + Returns ------- From f1332975e99cef0d4d3b66b808938e8d25d94dd1 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 15:32:36 +0200 Subject: [PATCH 03/23] ENH - #34932 - added type to argument --- 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 22964d1977244..f872d7c3f828f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6896,7 +6896,7 @@ def stack(self, level=-1, dropna=True): else: return stack(self, level, dropna=dropna) - def explode(self, column: Union[str, Tuple], ignore_index=False) -> "DataFrame": + def explode(self, column: Union[str, Tuple], ignore_index: bool) -> "DataFrame": """ Transform each element of a list-like to a row, replicating index values. From 4105930c3fc09e9d2112465297ddcb49375ddd85 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 15:45:00 +0200 Subject: [PATCH 04/23] ENH - #34932 - added ignore_index to Series.explode --- pandas/core/series.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ef47e52151961..b79db1b8a22d0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3716,7 +3716,7 @@ def reorder_levels(self, order) -> "Series": result.index = result.index.reorder_levels(order) return result - def explode(self) -> "Series": + def explode(self, ignore_index: bool) -> "Series": """ Transform each element of a list-like to a row, replicating the index values. @@ -3769,9 +3769,15 @@ def explode(self) -> "Series": values, counts = reshape.explode(np.asarray(self.array)) - result = self._constructor( - values, index=self.index.repeat(counts), name=self.name - ) + if ignore_index: + result = self._constructor( + values, index=range(len(values)), name=self.name + ) + else: + result = self._constructor( + values, index=self.index.repeat(counts), name=self.name + ) + return result def unstack(self, level=-1, fill_value=None): From 02e1266e5c4884209179e641a0ed69099e48e6f9 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 15:46:39 +0200 Subject: [PATCH 05/23] ENH - #34932 - added ignore_index to docstring Series.explode --- pandas/core/series.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index b79db1b8a22d0..5d9dc3409d9f3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3723,6 +3723,12 @@ def explode(self, ignore_index: bool) -> "Series": .. versionadded:: 0.25.0 + Parameters + ---------- + ignore_index : bool, default False + If True, the resulting index will be labeled 0, 1, …, n - 1. + + Returns ------- Series From 2f8019757391eba738ec0d6324d98f34220c1578 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 16:21:44 +0200 Subject: [PATCH 06/23] ENH - #34932 - added default to argument ignore_index frame --- pandas/core/frame.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f872d7c3f828f..7639e2c86a8c5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6896,7 +6896,9 @@ def stack(self, level=-1, dropna=True): else: return stack(self, level, dropna=dropna) - def explode(self, column: Union[str, Tuple], ignore_index: bool) -> "DataFrame": + def explode( + self, column: Union[str, Tuple], ignore_index: bool = False + ) -> "DataFrame": """ Transform each element of a list-like to a row, replicating index values. From 3e85845506c93070e89038cf5e19a076ac2b975c Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 16:21:53 +0200 Subject: [PATCH 07/23] ENH - #34932 - added default to argument ignore_index series --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 5d9dc3409d9f3..16c56d8ef4587 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3716,7 +3716,7 @@ def reorder_levels(self, order) -> "Series": result.index = result.index.reorder_levels(order) return result - def explode(self, ignore_index: bool) -> "Series": + def explode(self, ignore_index: bool = False) -> "Series": """ Transform each element of a list-like to a row, replicating the index values. From fd803acca46512cd1ace395b05789ae47cb89c09 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 16:32:10 +0200 Subject: [PATCH 08/23] ENH - #34932 - added test Series explode ignore_index --- pandas/tests/series/methods/test_explode.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/series/methods/test_explode.py b/pandas/tests/series/methods/test_explode.py index 979199e1efc62..62c326cba8025 100644 --- a/pandas/tests/series/methods/test_explode.py +++ b/pandas/tests/series/methods/test_explode.py @@ -119,3 +119,11 @@ def test_duplicate_index(): result = s.explode() expected = pd.Series([1, 2, 3, 4], index=[0, 0, 0, 0], dtype=object) tm.assert_series_equal(result, expected) + + +def test_ignore_index(): + # GH 34932 + s = pd.Series([[1, 2], [3, 4]]) + result = s.explode(ignore_index=True) + expected = pd.Series([1, 2, 3, 4], index=[0, 1, 2, 3]) + tm.assert_series_equal(result, expected) From 4f6a55bb6f42d55dadd04791fef85734c0e6aaeb Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 16:36:48 +0200 Subject: [PATCH 09/23] ENH - #34932 - added test DataFrame explode ignore_index --- pandas/tests/frame/methods/test_explode.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/frame/methods/test_explode.py b/pandas/tests/frame/methods/test_explode.py index bad8349ec977b..0ad0d52d5197d 100644 --- a/pandas/tests/frame/methods/test_explode.py +++ b/pandas/tests/frame/methods/test_explode.py @@ -162,3 +162,13 @@ def test_duplicate_index(input_dict, input_index, expected_dict, expected_index) result = df.explode("col1") expected = pd.DataFrame(expected_dict, index=expected_index, dtype=object) tm.assert_frame_equal(result, expected) + + +def test_ignore_index(): + # GH 34932 + df = pd.DataFrame({'id': range(0, 20, 10), + 'values': [list('ab'), list('cd')]}) + result = df.explode('values', ignore_index=True) + expected = pd.DataFrame({'id': [0, 0, 10, 10], + 'values': list('abcd')}, index=[0, 1, 2, 3]) + tm.assert_frame_equal(result, expected) From 0a531ddb3c2a1aff638cdb67b816cb06ec7b53a1 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 16:47:07 +0200 Subject: [PATCH 10/23] ENH - #34932 - added ignore_index explode to release notes --- doc/source/whatsnew/v1.1.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 2243790a663df..000acf94bf185 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -290,7 +290,8 @@ Other enhancements - Make ``option_context`` a :class:`contextlib.ContextDecorator`, which allows it to be used as a decorator over an entire function (:issue:`34253`). - :meth:`groupby.transform` now allows ``func`` to be ``pad``, ``backfill`` and ``cumcount`` (:issue:`31269`). - :meth:`~pandas.io.json.read_json` now accepts `nrows` parameter. (:issue:`33916`). -- :meth `~pandas.io.gbq.read_gbq` now allows to disable progress bar (:issue:`33360`). +- :meth:`~pandas.io.gbq.read_gbq` now allows to disable progress bar (:issue:`33360`). +- :meth:`~pandas.core.Series.explode` now accept ``ignore_index`` to reset the index, equal to ``pd.concat``, ``DataFrame.sort_values`` (:issue:`34932`). .. --------------------------------------------------------------------------- From 0ba378d038ece651a8a90a6668d07ae62709d70d Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 16:54:11 +0200 Subject: [PATCH 11/23] ENH - #34932 - fixed merge conflicts in release note --- doc/source/whatsnew/v1.1.0.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 000acf94bf185..cd53360f876cb 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -290,7 +290,12 @@ Other enhancements - Make ``option_context`` a :class:`contextlib.ContextDecorator`, which allows it to be used as a decorator over an entire function (:issue:`34253`). - :meth:`groupby.transform` now allows ``func`` to be ``pad``, ``backfill`` and ``cumcount`` (:issue:`31269`). - :meth:`~pandas.io.json.read_json` now accepts `nrows` parameter. (:issue:`33916`). +- :func:`concat` and :meth:`~DataFrame.append` now preserve extension dtypes, for example + combining a nullable integer column with a numpy integer column will no longer + result in object dtype but preserve the integer dtype (:issue:`33607`, :issue:`34339`). - :meth:`~pandas.io.gbq.read_gbq` now allows to disable progress bar (:issue:`33360`). +- :meth:`~pandas.io.gbq.read_gbq` now supports the ``max_results`` kwarg from ``pandas-gbq`` (:issue:`34639`). +- :meth:`DataFrame.to_html` and :meth:`DataFrame.to_string`'s ``col_space`` parameter now accepts a list of dict to change only some specific columns' width (:issue:`28917`). - :meth:`~pandas.core.Series.explode` now accept ``ignore_index`` to reset the index, equal to ``pd.concat``, ``DataFrame.sort_values`` (:issue:`34932`). .. --------------------------------------------------------------------------- From 94653199fab787f513c94b09ab3a8d9dd46a8a1a Mon Sep 17 00:00:00 2001 From: Erfan Nariman <34067903+erfannariman@users.noreply.github.com> Date: Mon, 22 Jun 2020 17:25:54 +0200 Subject: [PATCH 12/23] update release notes with suggestions Co-authored-by: Joris Van den Bossche --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 1105d2e7cd90b..0b74ea89eb4ea 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -298,7 +298,7 @@ Other enhancements - :meth:`~pandas.io.gbq.read_gbq` now allows to disable progress bar (:issue:`33360`). - :meth:`~pandas.io.gbq.read_gbq` now supports the ``max_results`` kwarg from ``pandas-gbq`` (:issue:`34639`). - :meth:`DataFrame.to_html` and :meth:`DataFrame.to_string`'s ``col_space`` parameter now accepts a list of dict to change only some specific columns' width (:issue:`28917`). -- :meth:`~pandas.core.Series.explode` now accept ``ignore_index`` to reset the index, equal to ``pd.concat``, ``DataFrame.sort_values`` (:issue:`34932`). +- :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to ``pd.concat`` or ``DataFrame.sort_values`` (:issue:`34932`). .. --------------------------------------------------------------------------- From 5c59b5418aa1e485a9f612e1794c0081600632ec Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 17:31:51 +0200 Subject: [PATCH 13/23] Added ibase default index instead of reset index --- pandas/core/frame.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7639e2c86a8c5..3fdcb2d6499ac 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6968,6 +6968,7 @@ def explode( result = df[column].explode() if ignore_index: result = df.drop([column], axis=1).join(result).reset_index(drop=True) + result.index = ibase.default_index(len(result)) else: result = df.drop([column], axis=1).join(result) result.index = self.index.take(result.index) From a4d28fe4446b40e2d9ff7d630223ee4034d7e6b2 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 17:36:40 +0200 Subject: [PATCH 14/23] Removed reset_index --- 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 b59931190d67b..480667fd087cd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6966,7 +6966,7 @@ def explode( assert df is not None # needed for mypy result = df[column].explode() if ignore_index: - result = df.drop([column], axis=1).join(result).reset_index(drop=True) + result = df.drop([column], axis=1).join(result) result.index = ibase.default_index(len(result)) else: result = df.drop([column], axis=1).join(result) From 5005f96af472675aed138eb0d18410c96ad72851 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 17:57:31 +0200 Subject: [PATCH 15/23] Add type to test Series --- pandas/tests/series/methods/test_explode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_explode.py b/pandas/tests/series/methods/test_explode.py index 62c326cba8025..9a91c549d7de2 100644 --- a/pandas/tests/series/methods/test_explode.py +++ b/pandas/tests/series/methods/test_explode.py @@ -125,5 +125,5 @@ def test_ignore_index(): # GH 34932 s = pd.Series([[1, 2], [3, 4]]) result = s.explode(ignore_index=True) - expected = pd.Series([1, 2, 3, 4], index=[0, 1, 2, 3]) + expected = pd.Series([1, 2, 3, 4], index=[0, 1, 2, 3], dtype=object) tm.assert_series_equal(result, expected) From b99ad4b92a46260a98db493d9af3047d506cc714 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 18:34:50 +0200 Subject: [PATCH 16/23] Changes CI black --- pandas/core/series.py | 4 +--- pandas/tests/frame/methods/test_explode.py | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 70a510a380c2a..58a32824c9a17 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3821,9 +3821,7 @@ def explode(self, ignore_index: bool = False) -> "Series": values, counts = reshape.explode(np.asarray(self.array)) if ignore_index: - result = self._constructor( - values, index=range(len(values)), name=self.name - ) + result = self._constructor(values, index=range(len(values)), name=self.name) else: result = self._constructor( values, index=self.index.repeat(counts), name=self.name diff --git a/pandas/tests/frame/methods/test_explode.py b/pandas/tests/frame/methods/test_explode.py index 0ad0d52d5197d..2bbe8ac2d5b81 100644 --- a/pandas/tests/frame/methods/test_explode.py +++ b/pandas/tests/frame/methods/test_explode.py @@ -166,9 +166,9 @@ def test_duplicate_index(input_dict, input_index, expected_dict, expected_index) def test_ignore_index(): # GH 34932 - df = pd.DataFrame({'id': range(0, 20, 10), - 'values': [list('ab'), list('cd')]}) - result = df.explode('values', ignore_index=True) - expected = pd.DataFrame({'id': [0, 0, 10, 10], - 'values': list('abcd')}, index=[0, 1, 2, 3]) + df = pd.DataFrame({"id": range(0, 20, 10), "values": [list("ab"), list("cd")]}) + result = df.explode("values", ignore_index=True) + expected = pd.DataFrame( + {"id": [0, 0, 10, 10], "values": list("abcd")}, index=[0, 1, 2, 3] + ) tm.assert_frame_equal(result, expected) From 47b985e7ddd8c3a81c21494cf8e1c1fda74cad13 Mon Sep 17 00:00:00 2001 From: Erfan Nariman | Veneficus Date: Mon, 22 Jun 2020 19:02:58 +0200 Subject: [PATCH 17/23] Removed double line break in docstrings --- pandas/core/frame.py | 1 - pandas/core/series.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 480667fd087cd..0513f23e861dd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6910,7 +6910,6 @@ def explode( ignore_index : bool, default False If True, the resulting index will be labeled 0, 1, …, n - 1. - Returns ------- DataFrame diff --git a/pandas/core/series.py b/pandas/core/series.py index 58a32824c9a17..79bba58f14056 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3773,7 +3773,6 @@ def explode(self, ignore_index: bool = False) -> "Series": ignore_index : bool, default False If True, the resulting index will be labeled 0, 1, …, n - 1. - Returns ------- Series From 92bcb89e926da774356d8c3c2835381a95c8ac12 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Mon, 22 Jun 2020 21:11:21 +0200 Subject: [PATCH 18/23] removed redundant repetition of line --- pandas/core/frame.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0513f23e861dd..44bb0c47f153d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6964,11 +6964,10 @@ def explode( # TODO: use overload to refine return type of reset_index assert df is not None # needed for mypy result = df[column].explode() + result = df.drop([column], axis=1).join(result) if ignore_index: - result = df.drop([column], axis=1).join(result) result.index = ibase.default_index(len(result)) else: - result = df.drop([column], axis=1).join(result) result.index = self.index.take(result.index) result = result.reindex(columns=self.columns, copy=False) From 8551d7075bd337df1cdc17f2b80ca1fe49869efb Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 24 Jun 2020 01:01:21 +0200 Subject: [PATCH 19/23] Version added to docstring argument --- pandas/core/frame.py | 2 ++ pandas/core/series.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 44bb0c47f153d..2ba9372d531ec 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6910,6 +6910,8 @@ def explode( ignore_index : bool, default False If True, the resulting index will be labeled 0, 1, …, n - 1. + .. versionadded:: 1.1.0 + Returns ------- DataFrame diff --git a/pandas/core/series.py b/pandas/core/series.py index 79bba58f14056..1b0acaa15d06d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3773,6 +3773,8 @@ def explode(self, ignore_index: bool = False) -> "Series": ignore_index : bool, default False If True, the resulting index will be labeled 0, 1, …, n - 1. + .. versionadded:: 1.1.0 + Returns ------- Series From 7537ec0fa8af0ba1cbc971e8bada5d512bc5def6 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 24 Jun 2020 01:23:19 +0200 Subject: [PATCH 20/23] Removed name from result series --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1b0acaa15d06d..5eda2a0feae8c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3822,7 +3822,7 @@ def explode(self, ignore_index: bool = False) -> "Series": values, counts = reshape.explode(np.asarray(self.array)) if ignore_index: - result = self._constructor(values, index=range(len(values)), name=self.name) + result = self._constructor(values, index=range(len(values))) else: result = self._constructor( values, index=self.index.repeat(counts), name=self.name From 64fa916d105923e6daac1c0310b95c9128942176 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Wed, 24 Jun 2020 09:31:16 -0400 Subject: [PATCH 21/23] Update doc/source/whatsnew/v1.1.0.rst Co-authored-by: Tom Augspurger --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 0b74ea89eb4ea..b1143a2bac1db 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -298,7 +298,7 @@ Other enhancements - :meth:`~pandas.io.gbq.read_gbq` now allows to disable progress bar (:issue:`33360`). - :meth:`~pandas.io.gbq.read_gbq` now supports the ``max_results`` kwarg from ``pandas-gbq`` (:issue:`34639`). - :meth:`DataFrame.to_html` and :meth:`DataFrame.to_string`'s ``col_space`` parameter now accepts a list of dict to change only some specific columns' width (:issue:`28917`). -- :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to ``pd.concat`` or ``DataFrame.sort_values`` (:issue:`34932`). +- :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to :meth:`pd.concat` or :meth:`DataFrame.sort_values` (:issue:`34932`). .. --------------------------------------------------------------------------- From 3110aae0987156009ea83e4f3f1c4aa083df3af0 Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 24 Jun 2020 16:51:57 +0200 Subject: [PATCH 22/23] Added meth refs --- doc/source/whatsnew/v1.1.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 0b74ea89eb4ea..b1143a2bac1db 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -298,7 +298,7 @@ Other enhancements - :meth:`~pandas.io.gbq.read_gbq` now allows to disable progress bar (:issue:`33360`). - :meth:`~pandas.io.gbq.read_gbq` now supports the ``max_results`` kwarg from ``pandas-gbq`` (:issue:`34639`). - :meth:`DataFrame.to_html` and :meth:`DataFrame.to_string`'s ``col_space`` parameter now accepts a list of dict to change only some specific columns' width (:issue:`28917`). -- :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to ``pd.concat`` or ``DataFrame.sort_values`` (:issue:`34932`). +- :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to :meth:`pd.concat` or :meth:`DataFrame.sort_values` (:issue:`34932`). .. --------------------------------------------------------------------------- From dc45b71fc26b40d5eb49788620a2a2e75da2446e Mon Sep 17 00:00:00 2001 From: Erfan Nariman Date: Wed, 24 Jun 2020 16:56:33 +0200 Subject: [PATCH 23/23] Added different approach constructor --- pandas/core/series.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 5eda2a0feae8c..9ab9328962bdf 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3822,11 +3822,11 @@ def explode(self, ignore_index: bool = False) -> "Series": values, counts = reshape.explode(np.asarray(self.array)) if ignore_index: - result = self._constructor(values, index=range(len(values))) + index = ibase.default_index(len(values)) else: - result = self._constructor( - values, index=self.index.repeat(counts), name=self.name - ) + index = self.index.repeat(counts) + + result = self._constructor(values, index=index, name=self.name) return result