Skip to content
Open
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions mapclassify/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
def pytest_configure(config): # noqa: ARG001
"""PyTest session attributes, methods, etc."""

pytest.image_comp_kws = {"extensions": ["png"], "tol": 0.35, "remove_text": True}
pytest.image_comp_kws = {
"extensions": ["png"],
"remove_text": True,
"style": "mpl20",
}
pytest.image_comp_kws_legend_text = {
"extensions": ["png"],
"tol": 2.8,
"remove_text": True,
"style": "mpl20",
}
25 changes: 21 additions & 4 deletions mapclassify/tests/test_legendgram.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import copy

import geopandas as gpd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pytest
from libpysal import examples
from matplotlib.testing.decorators import image_comparison
from packaging.version import Version

from mapclassify import EqualInterval, Quantiles
from mapclassify.legendgram import _legendgram

GPD_113_dev = Version(gpd.__version__).is_devrelease and Version(
Version(gpd.__version__).base_version
) >= Version("1.1.2")


no_data_warning = pytest.warns(
UserWarning,
match="There is no data associated with the `ax`",
Expand Down Expand Up @@ -122,7 +130,10 @@ def test_legendgram_position(self):
self.classifier, ax=ax, loc="upper right", legend_size=("40%", "30%")
)

@image_comparison(["legendgram_map"], **pytest.image_comp_kws)
map_image_comp_kws = copy.deepcopy(pytest.image_comp_kws)
map_image_comp_kws["tol"] = 2.14

@image_comparison(["legendgram_map"], **map_image_comp_kws)
def test_legendgram_map(self):
"""Test with geopandas map"""
data = gpd.read_file(examples.get_path("south.shp")).to_crs(epsg=5070)
Expand All @@ -145,21 +156,27 @@ def test_legendgram_kwargs(self):
orientation="horizontal",
)

@pytest.mark.skipif(GPD_113_dev, reason="Fixed in GeoPandas dev as of [2026/06]")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we skipping this? Also, the plotting change in GeoPandas is targeting 1.2, there will be 1.1.4 release without it, so the condition might break.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping because the test fails on in bleeding edge geopandas, since no warnings are thrown and I thought that logic path was going in geopandas anyway -- but perhaps I misunderstood. It was late and I wasn't sure if I wanted to add in the dev environment logic specifically only for this. I can probably figure out some other "clever" way of handling if we aren't comfortable with this "solution" (quotes are very on purpose).

Other than this specific thing, how do you find this testing update?

@image_comparison(["legendgram_most_recent_cmap"], **pytest.image_comp_kws)
def test_legendgram_most_recent_cmap(self):
"""Test most recent colormap legendgram appearance"""
data = gpd.read_file(examples.get_path("south.shp")).to_crs(epsg=5070)
ax = data.plot("DV80", k=10, scheme="Quantiles", cmap="Blues")
data.plot("DV80", ax=ax, k=10, scheme="Quantiles", cmap="Greens")
classifier = Quantiles(data["DV80"].values, k=10)

with pytest.warns(
UserWarning,
match=(
"There are 2 unique colormaps associated with the axes. "
"Defaulting to most recent colormap: 'Greens'"
),
):
classifier.plot_legendgram(
ax=ax, legend_size=("50%", "20%"), loc="upper left", clip=(2, 10)
)
kwargs = {
"ax": ax,
"legend_size": ("50%", "20%"),
"loc": "upper left",
"clip": (2, 10),
}
classifier.plot_legendgram(**kwargs)
ax.set_axis_off()
13 changes: 10 additions & 3 deletions mapclassify/tests/test_mapclassify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import types

import matplotlib
import numpy
import pandas
import pytest
Expand Down Expand Up @@ -788,17 +789,23 @@ def setup_method(self):

@image_comparison(["test_histogram_plot"], **pytest.image_comp_kws)
def test_histogram_plot(self):
ax = Quantiles(self.data).plot_histogram()
fig, ax = matplotlib.pyplot.subplots(**{"figsize": (8, 6), "dpi": 100})
ax = Quantiles(self.data).plot_histogram(ax=ax)
ax.set(xlabel=None, ylabel=None)
return ax.get_figure()

@image_comparison(["test_histogram_plot_despine"], **pytest.image_comp_kws)
def test_histogram_plot_despine(self):
ax = Quantiles(self.data).plot_histogram(despine=False)
fig, ax = matplotlib.pyplot.subplots(**{"figsize": (8, 6), "dpi": 100})
ax = Quantiles(self.data).plot_histogram(ax=ax, despine=False)
ax.set(xlabel=None, ylabel=None)
return ax.get_figure()

@image_comparison(["test_histogram_plot_linewidth"], **pytest.image_comp_kws)
def test_histogram_plot_linewidth(self):
fig, ax = matplotlib.pyplot.subplots(**{"figsize": (8, 6), "dpi": 100})
ax = Quantiles(self.data).plot_histogram(
linewidth=3, linecolor="red", color="yellow"
ax=ax, linewidth=3, linecolor="red", color="yellow"
)
ax.set(xlabel=None, ylabel=None)
return ax.get_figure()
9 changes: 9 additions & 0 deletions mapclassify/tests/test_value_by_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def setup_method(self):
@image_comparison(["no_classify_default"], **pytest.image_comp_kws)
def test_no_classify_default(self):
fig, ax = vba_choropleth(self.x, self.y, self.gdf)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -26,6 +27,7 @@ def test_pass_in_ax(self):
fig = plt.figure()
ax = fig.add_subplot(111)
fig, ax = vba_choropleth(self.x, self.y, self.gdf, ax=ax)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -40,6 +42,7 @@ def test_classify_xy_redblue(self):
y_classification_kwds={"classifier": "quantiles"},
cmap="RdBu",
)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -57,6 +60,7 @@ def test_divergent_revert_alpha_min_alpha(self):
revert_alpha=True,
min_alpha=0.5,
)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -65,6 +69,7 @@ def test_divergent_revert_alpha_min_alpha(self):
def test_userdefined_colors(self):
color_list = ["#a1dab4", "#41b6c4", "#225ea8"]
fig, ax = vba_choropleth(self.x, self.y, self.gdf, cmap=color_list)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -76,6 +81,7 @@ def test_shifted_colormap(self):
assert mid08.name == "RdBu_08"

fig, ax = vba_choropleth(self.x, self.y, self.gdf, cmap=mid08)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -87,6 +93,7 @@ def test_truncated_colormap(self):
assert trunc0206.name == "trunc(RdBu,0.20,0.60)"

fig, ax = vba_choropleth(self.x, self.y, self.gdf, cmap=trunc0206)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -111,6 +118,7 @@ def test_legend(self):
y_classification_kwds={"classifier": "quantiles"},
legend=True,
)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Expand All @@ -126,6 +134,7 @@ def test_legend_kwargs(self):
legend=True,
legend_kwargs={"x_label": self.x, "y_label": self.y},
)
ax.set(xlabel=None, ylabel=None)

assert isinstance(fig, matplotlib.figure.Figure)
assert isinstance(ax, matplotlib.axes.Axes)
Loading