-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MNT] handle deprecation of
pandas.DataFrame.applymap
(#170)
This PR handles deprecation of `DataFrame.applymap`, by replacing instances with a version-conditional call. Additionally, also fixes a minor, unrelated docstring typo.
- Loading branch information
Showing
3 changed files
with
32 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 -u | ||
"""Utilities for pandas adapbation.""" | ||
|
||
__author__ = ["fkiraly"] | ||
|
||
|
||
def df_map(x): | ||
"""Access map or applymap, of DataFrame. | ||
In pandas 2.1.0, applymap was deprecated in favor of the newly introduced map. | ||
To ensure compatibility with older versions, we use map if available, | ||
otherwise applymap. | ||
Parameters | ||
---------- | ||
x : assumed pd.DataFrame | ||
Returns | ||
------- | ||
x.map, if available, otherwise x.applymap | ||
Note: returns method itself, not result of method call | ||
""" | ||
if hasattr(x, "map"): | ||
return x.map | ||
else: | ||
return x.applymap |