Skip to content

Commit

Permalink
python Series alias method
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 22, 2021
1 parent b56c930 commit 3e0e79e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions py-polars/docs/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Manipulation/ selection
.. autosummary::
:toctree: api/

Series.alias
Series.rename
Series.limit
Series.slice
Expand Down
21 changes: 18 additions & 3 deletions py-polars/polars/eager/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,23 @@ def name(self) -> str:
"""
return self._s.name()

def alias(self, name: str) -> "Series":
"""
Rename the Series
Parameters
----------
name
New name
Returns
-------
"""
s = self.clone()
s._s.rename(name)
return s

def rename(self, name: str, in_place: bool = False) -> Optional["Series"]:
"""
Rename this Series.
Expand Down Expand Up @@ -930,9 +947,7 @@ def rename(self, name: str, in_place: bool = False) -> Optional["Series"]:
self._s.rename(name)
return None
else:
s = self.clone()
s._s.rename(name)
return s
return self.alias(name)

def chunk_lengths(self) -> tp.List[int]:
"""
Expand Down

0 comments on commit 3e0e79e

Please sign in to comment.