Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress pandas FutureWarning for applymap() #70

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions audplot/core/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import typing
import warnings

import matplotlib
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -174,10 +175,15 @@ def confusion_matrix(
cm = pd.DataFrame(cm, index=labels)

# Set format of first row labels in confusion matrix
if percentage:
annot = cm.applymap(lambda x: f"{100 * x:.0f}%")
else:
annot = cm.applymap(lambda x: human_format(x))
with warnings.catch_warnings():
# Catch warning,
# to still support older pandas versions.
# See https://github.com/audeering/audplot/pull/69
warnings.simplefilter(action="ignore", category=FutureWarning)
if percentage:
annot = cm.applymap(lambda x: f"{100 * x:.0f}%")
else:
annot = cm.applymap(lambda x: human_format(x))

# Add a second row of annotations if requested
if show_both:
Expand All @@ -188,10 +194,16 @@ def confusion_matrix(
normalize=not percentage,
)
cm2 = pd.DataFrame(cm2, index=labels)
if percentage:
annot2 = cm2.applymap(lambda x: human_format(x))
else:
annot2 = cm2.applymap(lambda x: f"{100 * x:.0f}%")

with warnings.catch_warnings():
# Catch warning,
# to still support older pandas versions.
# See https://github.com/audeering/audplot/pull/69
warnings.simplefilter(action="ignore", category=FutureWarning)
if percentage:
annot2 = cm2.applymap(lambda x: human_format(x))
else:
annot2 = cm2.applymap(lambda x: f"{100 * x:.0f}%")

# Combine strings from two dataframes
# by vectorizing the underlying function.
Expand Down
Loading