forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add axis parameter to add_prefix and add_suffix (pandas-dev#48085)
* Add axis parameter to add_prefix and add_suffix * Add axis parameter to add_prefix and add_suffix * Added testcases * docstring update * docstring update * updated whatsnew file * updated whatsnew file * updated whatsnew file * review comments * address merge conflixts * address merge conflixts * updated whatsnew * review comments * review comments * review comments
- Loading branch information
Showing
4 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
from pandas import Index | ||
import pandas._testing as tm | ||
|
||
|
||
def test_add_prefix_suffix(string_series): | ||
with_prefix = string_series.add_prefix("foo#") | ||
expected = Index([f"foo#{c}" for c in string_series.index]) | ||
tm.assert_index_equal(with_prefix.index, expected) | ||
|
||
with_suffix = string_series.add_suffix("#foo") | ||
expected = Index([f"{c}#foo" for c in string_series.index]) | ||
tm.assert_index_equal(with_suffix.index, expected) | ||
|
||
with_pct_prefix = string_series.add_prefix("%") | ||
expected = Index([f"%{c}" for c in string_series.index]) | ||
tm.assert_index_equal(with_pct_prefix.index, expected) | ||
|
||
with_pct_suffix = string_series.add_suffix("%") | ||
expected = Index([f"{c}%" for c in string_series.index]) | ||
tm.assert_index_equal(with_pct_suffix.index, expected) | ||
|
||
|
||
def test_add_prefix_suffix_axis(string_series): | ||
# GH 47819 | ||
with_prefix = string_series.add_prefix("foo#", axis=0) | ||
expected = Index([f"foo#{c}" for c in string_series.index]) | ||
tm.assert_index_equal(with_prefix.index, expected) | ||
|
||
with_pct_suffix = string_series.add_suffix("#foo", axis=0) | ||
expected = Index([f"{c}#foo" for c in string_series.index]) | ||
tm.assert_index_equal(with_pct_suffix.index, expected) | ||
|
||
|
||
def test_add_prefix_suffix_invalid_axis(string_series): | ||
with pytest.raises(ValueError, match="No axis named 1 for object type Series"): | ||
string_series.add_prefix("foo#", axis=1) | ||
|
||
with pytest.raises(ValueError, match="No axis named 1 for object type Series"): | ||
string_series.add_suffix("foo#", axis=1) |