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

TST: matplotlib test compatibility #150

Merged
merged 1 commit into from
Jan 16, 2025
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
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
Loading