Skip to content

Commit

Permalink
TST: matplotlib test compatibility (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis authored Jan 16, 2025
1 parent f77706b commit 9a2d54d
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions pointpats/tests/test_kde.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import numpy as np
import pytest
from packaging.version import Version

from pointpats import plot_density

matplotlib = pytest.importorskip("matplotlib")
statsmodels = pytest.importorskip("statsmodels")
KDEpy = pytest.importorskip("KDEpy")

MPL_310 = Version(matplotlib.__version__) >= Version("3.10.0")


@pytest.mark.skipif(not MPL_310, reason="ContourSet is composed differently in < 3.10")
class TestDensity:
def setup_method(self):
self.points = np.array(
Expand All @@ -30,7 +34,7 @@ def setup_method(self):
def test_default(self):
ax = plot_density(self.points, 10)
contourset = ax.collections[0]
assert len(contourset.collections) == 12
assert len(ax.collections[0].get_paths()) == 12
assert not contourset.filled
np.testing.assert_array_equal(contourset.get_linewidths(), np.array([1.5] * 12))
np.testing.assert_array_equal(
Expand All @@ -40,33 +44,28 @@ def test_default(self):

def test_bandwidth(self):
ax = plot_density(self.points, 1)
contourset = ax.collections[0]
assert len(contourset.collections) == 10
assert len(ax.collections[0].get_paths()) == 10

def test_resolution(self):
ax = plot_density(self.points, 10, resolution=200)
contourset = ax.collections[0]
collections = contourset.collections
assert len(collections) == 12
assert len(contourset.get_paths()) == 12

def test_margin(self):
ax = plot_density(self.points, 10, margin=0.3)
contourset = ax.collections[0]
collections = contourset.collections
assert len(collections) == 12
assert len(contourset.get_paths()) == 12

def test_kdepy(self):
ax = plot_density(self.points, 10, kernel="gaussian")
contourset = ax.collections[0]
collections = contourset.collections
assert len(collections) == 12
assert len(contourset.get_paths()) == 12
np.testing.assert_array_equal(contourset.get_linewidths(), np.array([1.5] * 12))

def test_levels(self):
ax = plot_density(self.points, 10, levels=5)
contourset = ax.collections[0]
collections = contourset.collections
assert len(collections) == 7
assert len(contourset.get_paths()) == 7

def test_fill(self):
ax = plot_density(self.points, 10, fill=True)
Expand All @@ -84,17 +83,15 @@ def test_geopandas(self):
gs = geopandas.GeoSeries.from_xy(*self.points.T)
ax = plot_density(gs, 10)
contourset = ax.collections[0]
collections = contourset.collections
assert len(collections) == 12
assert len(contourset.get_paths()) == 12
np.testing.assert_array_equal(contourset.get_linewidths(), np.array([1.5] * 12))

def test_kwargs(self):
ax = plot_density(
self.points, 10, cmap="magma", linewidths=0.5, linestyles="-."
)
contourset = ax.collections[0]
collections = contourset.collections
assert len(collections) == 12
assert len(contourset.get_paths()) == 12
np.testing.assert_array_equal(contourset.get_linewidths(), np.array([0.5] * 12))

np.testing.assert_array_equal(
Expand Down

0 comments on commit 9a2d54d

Please sign in to comment.