From f69e0c35d1c2545e9d3a35993f23c24ad8b4ac93 Mon Sep 17 00:00:00 2001 From: Varun Shrivastava Date: Fri, 9 Jul 2021 11:04:09 +0530 Subject: [PATCH 1/6] Fixed Issue #42447 --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d928195bf2a10..51e09ca1b5dea 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ structures designed to make working with "relational" or "labeled" data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, **real world** data analysis in Python. Additionally, it has -the broader goal of becoming **the most powerful and flexible open source data -analysis / manipulation tool available in any language**. It is already well on +the broader goal of becoming **the most powerful and flexible open-source data +analysis/manipulation tool available in any language**. It is already well on its way towards this goal. ## Main Features @@ -107,14 +107,14 @@ pip install pandas See the [full installation instructions](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies) for minimum supported versions of required, recommended and optional dependencies. ## Installation from sources -To install pandas from source you need [Cython](https://cython.org/) in addition to the normal +To install pandas the from source you need [Cython](https://cython.org/) in addition to the normal dependencies above. Cython can be installed from PyPI: ```sh pip install cython ``` -In the `pandas` directory (same one where you found this file after +In the `pandas` directory (the same one where you found this file after cloning the git repo), execute: ```sh @@ -160,14 +160,14 @@ Most development discussions take place on GitHub in this repo. Further, the [pa All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. -A detailed overview on how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub. +A detailed overview of how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub. -If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are a number of issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start out. +If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are several issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start. -You can also triage issues which may include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas). +You can also triage issues which may include reproducing bug reports or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas). Or maybe through using pandas you have an idea of your own or are looking for something in the documentation and thinking ‘this can be improved’...you can do something about it! -Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas). +Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or [Gitter](https://gitter.im/pydata/pandas). As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/pandas/blob/master/.github/CODE_OF_CONDUCT.md) From b4ee138c2e735b25d19319a7a83a6fcb6039538d Mon Sep 17 00:00:00 2001 From: Varun Shrivastava Date: Mon, 29 Nov 2021 19:48:42 +0530 Subject: [PATCH 2/6] Deprecate mapper argument in rename #44627 --- pandas/core/frame.py | 2 +- pandas/core/generic.py | 2 +- pandas/core/series.py | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 803d1c914c954..c5d50558b595d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5192,7 +5192,7 @@ def rename( 2 2 5 4 3 6 """ - return super().rename( + return super()._rename( mapper=mapper, index=index, columns=columns, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4aff7acc4c6fb..f7cc12ae7c9fe 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -989,7 +989,7 @@ def squeeze(self, axis=None): # ---------------------------------------------------------------------- # Rename - def rename( + def _rename( self: NDFrameT, mapper: Renamer | None = None, *, diff --git a/pandas/core/series.py b/pandas/core/series.py index ffa31b4f66211..f0aa03a099b9f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4468,10 +4468,8 @@ def align( def rename( self, - mapper=None, - *, index=None, - columns=None, + *, axis=None, copy=True, inplace=False, @@ -4546,7 +4544,7 @@ def rename( if mapper is None: mapper = index if callable(mapper) or is_dict_like(mapper): - return super().rename( + return super()._rename( mapper, copy=copy, inplace=inplace, level=level, errors=errors ) else: From 3437dceb42b166451416fe467556fa37b00ce79b Mon Sep 17 00:00:00 2001 From: Varun Shrivastava Date: Mon, 29 Nov 2021 19:53:54 +0530 Subject: [PATCH 3/6] Revert "Fixed Issue #42447" This reverts commit f69e0c35d1c2545e9d3a35993f23c24ad8b4ac93. --- README.md | 16 ++++++++-------- pandas/core/series.py | 12 ++++-------- pandas/tests/series/methods/test_rename.py | 6 ------ 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c952a09acf766..7bb77c70ab682 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ structures designed to make working with "relational" or "labeled" data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, **real world** data analysis in Python. Additionally, it has -the broader goal of becoming **the most powerful and flexible open-source data -analysis/manipulation tool available in any language**. It is already well on +the broader goal of becoming **the most powerful and flexible open source data +analysis / manipulation tool available in any language**. It is already well on its way towards this goal. ## Main Features @@ -107,14 +107,14 @@ pip install pandas See the [full installation instructions](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies) for minimum supported versions of required, recommended and optional dependencies. ## Installation from sources -To install pandas the from source you need [Cython](https://cython.org/) in addition to the normal +To install pandas from source you need [Cython](https://cython.org/) in addition to the normal dependencies above. Cython can be installed from PyPI: ```sh pip install cython ``` -In the `pandas` directory (the same one where you found this file after +In the `pandas` directory (same one where you found this file after cloning the git repo), execute: ```sh @@ -160,14 +160,14 @@ Most development discussions take place on GitHub in this repo. Further, the [pa All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. -A detailed overview of how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub. +A detailed overview on how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub. -If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are several issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start. +If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are a number of issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start out. -You can also triage issues which may include reproducing bug reports or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas). +You can also triage issues which may include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas). Or maybe through using pandas you have an idea of your own or are looking for something in the documentation and thinking ‘this can be improved’...you can do something about it! -Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or [Gitter](https://gitter.im/pydata/pandas). +Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas). As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/pandas/blob/master/.github/CODE_OF_CONDUCT.md) diff --git a/pandas/core/series.py b/pandas/core/series.py index f0aa03a099b9f..7c04dd005fb96 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4491,7 +4491,7 @@ def rename( ---------- axis : {0 or "index"} Unused. Accepted for compatibility with DataFrame method only. - mapper : scalar, hashable sequence, dict-like or function, optional + index : scalar, hashable sequence, dict-like or function, optional Functions or dict-like are transformations to apply to the index. Scalar or hashable sequence-like will alter the ``Series.name`` @@ -4539,16 +4539,12 @@ def rename( # Make sure we raise if an invalid 'axis' is passed. axis = self._get_axis_number(axis) - if index is not None and mapper is not None: - raise TypeError("Cannot specify both 'mapper' and 'index'") - if mapper is None: - mapper = index - if callable(mapper) or is_dict_like(mapper): + if callable(index) or is_dict_like(index): return super()._rename( - mapper, copy=copy, inplace=inplace, level=level, errors=errors + index, copy=copy, inplace=inplace, level=level, errors=errors ) else: - return self._set_name(mapper, inplace=inplace) + return self._set_name(index, inplace=inplace) @overload def set_axis( diff --git a/pandas/tests/series/methods/test_rename.py b/pandas/tests/series/methods/test_rename.py index 3425dd8f019e7..90c8f775586e6 100644 --- a/pandas/tests/series/methods/test_rename.py +++ b/pandas/tests/series/methods/test_rename.py @@ -105,12 +105,6 @@ def test_rename_callable(self): assert result.name == expected.name - def test_rename_method_and_index(self): - # GH 40977 - ser = Series([1, 2]) - with pytest.raises(TypeError, match="Cannot specify both 'mapper' and 'index'"): - ser.rename(str, index=str) - def test_rename_none(self): # GH 40977 ser = Series([1, 2], name="foo") From 37fcce81ef1f5ff1c23c9bc5f1cc7a7b67b02bd8 Mon Sep 17 00:00:00 2001 From: Varun Shrivastava Date: Mon, 29 Nov 2021 19:53:54 +0530 Subject: [PATCH 4/6] Revert "Fixed Issue #42447" This reverts commit f69e0c35d1c2545e9d3a35993f23c24ad8b4ac93. --- README.md | 16 ++++++++-------- pandas/core/generic.py | 4 ++-- pandas/core/series.py | 12 ++++-------- pandas/tests/series/methods/test_rename.py | 6 ------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index c952a09acf766..7bb77c70ab682 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ structures designed to make working with "relational" or "labeled" data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, **real world** data analysis in Python. Additionally, it has -the broader goal of becoming **the most powerful and flexible open-source data -analysis/manipulation tool available in any language**. It is already well on +the broader goal of becoming **the most powerful and flexible open source data +analysis / manipulation tool available in any language**. It is already well on its way towards this goal. ## Main Features @@ -107,14 +107,14 @@ pip install pandas See the [full installation instructions](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies) for minimum supported versions of required, recommended and optional dependencies. ## Installation from sources -To install pandas the from source you need [Cython](https://cython.org/) in addition to the normal +To install pandas from source you need [Cython](https://cython.org/) in addition to the normal dependencies above. Cython can be installed from PyPI: ```sh pip install cython ``` -In the `pandas` directory (the same one where you found this file after +In the `pandas` directory (same one where you found this file after cloning the git repo), execute: ```sh @@ -160,14 +160,14 @@ Most development discussions take place on GitHub in this repo. Further, the [pa All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. -A detailed overview of how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub. +A detailed overview on how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**. There is also an [overview](.github/CONTRIBUTING.md) on GitHub. -If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are several issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start. +If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are a number of issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start out. -You can also triage issues which may include reproducing bug reports or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas). +You can also triage issues which may include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas). Or maybe through using pandas you have an idea of your own or are looking for something in the documentation and thinking ‘this can be improved’...you can do something about it! -Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or [Gitter](https://gitter.im/pydata/pandas). +Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas). As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/pandas/blob/master/.github/CODE_OF_CONDUCT.md) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f7cc12ae7c9fe..530d916cb14eb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4418,7 +4418,7 @@ def add_prefix(self: NDFrameT, prefix: str) -> NDFrameT: # expected "NDFrameT") # error: Argument 1 to "rename" of "NDFrame" has incompatible type # "**Dict[str, partial[str]]"; expected "Union[str, int, None]" - return self.rename(**mapper) # type: ignore[return-value, arg-type] + return self.rename(**mapper) @final def add_suffix(self: NDFrameT, suffix: str) -> NDFrameT: @@ -4482,7 +4482,7 @@ def add_suffix(self: NDFrameT, suffix: str) -> NDFrameT: # expected "NDFrameT") # error: Argument 1 to "rename" of "NDFrame" has incompatible type # "**Dict[str, partial[str]]"; expected "Union[str, int, None]" - return self.rename(**mapper) # type: ignore[return-value, arg-type] + return self.rename(**mapper) def sort_values( self, diff --git a/pandas/core/series.py b/pandas/core/series.py index f0aa03a099b9f..7c04dd005fb96 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4491,7 +4491,7 @@ def rename( ---------- axis : {0 or "index"} Unused. Accepted for compatibility with DataFrame method only. - mapper : scalar, hashable sequence, dict-like or function, optional + index : scalar, hashable sequence, dict-like or function, optional Functions or dict-like are transformations to apply to the index. Scalar or hashable sequence-like will alter the ``Series.name`` @@ -4539,16 +4539,12 @@ def rename( # Make sure we raise if an invalid 'axis' is passed. axis = self._get_axis_number(axis) - if index is not None and mapper is not None: - raise TypeError("Cannot specify both 'mapper' and 'index'") - if mapper is None: - mapper = index - if callable(mapper) or is_dict_like(mapper): + if callable(index) or is_dict_like(index): return super()._rename( - mapper, copy=copy, inplace=inplace, level=level, errors=errors + index, copy=copy, inplace=inplace, level=level, errors=errors ) else: - return self._set_name(mapper, inplace=inplace) + return self._set_name(index, inplace=inplace) @overload def set_axis( diff --git a/pandas/tests/series/methods/test_rename.py b/pandas/tests/series/methods/test_rename.py index 3425dd8f019e7..90c8f775586e6 100644 --- a/pandas/tests/series/methods/test_rename.py +++ b/pandas/tests/series/methods/test_rename.py @@ -105,12 +105,6 @@ def test_rename_callable(self): assert result.name == expected.name - def test_rename_method_and_index(self): - # GH 40977 - ser = Series([1, 2]) - with pytest.raises(TypeError, match="Cannot specify both 'mapper' and 'index'"): - ser.rename(str, index=str) - def test_rename_none(self): # GH 40977 ser = Series([1, 2], name="foo") From aafd33c1413ee129ab81ef15a5375ea24c8cb201 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Thu, 2 Dec 2021 14:57:36 +0000 Subject: [PATCH 5/6] Update pandas/core/generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 386ce9003b295..bfdfe95d9c6b0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4418,7 +4418,7 @@ def add_prefix(self: NDFrameT, prefix: str) -> NDFrameT: # expected "NDFrameT") # error: Argument 1 to "rename" of "NDFrame" has incompatible type # "**Dict[str, partial[str]]"; expected "Union[str, int, None]" - return self._rename(**mapper) # type: ignore[return-value, arg-type] + return self._rename(**mapper) # type: ignore[return-value, arg-type] @final def add_suffix(self: NDFrameT, suffix: str) -> NDFrameT: From d6d011cb1f1ce4a900aaa993cad25be4a213a380 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Thu, 2 Dec 2021 14:57:48 +0000 Subject: [PATCH 6/6] Update pandas/core/generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bfdfe95d9c6b0..b9169c8595324 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4482,7 +4482,7 @@ def add_suffix(self: NDFrameT, suffix: str) -> NDFrameT: # expected "NDFrameT") # error: Argument 1 to "rename" of "NDFrame" has incompatible type # "**Dict[str, partial[str]]"; expected "Union[str, int, None]" - return self._rename(**mapper) # type: ignore[return-value, arg-type] + return self._rename(**mapper) # type: ignore[return-value, arg-type] def sort_values( self,