Skip to content

Commit

Permalink
Use math.isclose for zero variance check
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Dec 12, 2020
1 parent 92c9aa4 commit 9e9427e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions seaborn/distributions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Plotting functions for visualizing distributions."""
from numbers import Number
from functools import partial
import math
import warnings

import numpy as np
Expand Down Expand Up @@ -300,7 +301,7 @@ def _compute_univariate_density(
observations = sub_data[data_variable]

observation_variance = observations.var()
if np.isclose(observation_variance, 0) or np.isnan(observation_variance):
if math.isclose(observation_variance, 0) or np.isnan(observation_variance):
msg = "Dataset has 0 variance; skipping density estimate."
warnings.warn(msg, UserWarning)
continue
Expand Down Expand Up @@ -1072,7 +1073,7 @@ def plot_bivariate_density(

# Check that KDE will not error out
variance = observations[["x", "y"]].var()
if np.isclose(variance, 0).any() or variance.isna().any():
if any(math.isclose(x, 0) for x in variance) or variance.isna().any():
msg = "Dataset has 0 variance; skipping density estimate."
warnings.warn(msg, UserWarning)
continue
Expand Down

0 comments on commit 9e9427e

Please sign in to comment.