Skip to content

Commit

Permalink
Update & test min reqs + handling upstream deprecation warnings (#169)
Browse files Browse the repository at this point in the history
* resolves #162, etc.

* minimum environment testing

* add min testing to workflow

* matplotlib==2.2.4

* update min mpl vers & give envs BASE flag

* min pins based on NEP 29

* min pin geopandas 0.9.0
  • Loading branch information
jGaboardi authored Nov 15, 2022
1 parent 8dba8c4 commit 7750929
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 56 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ jobs:
matrix:
os: [ubuntu-latest]
environment-file:
- ci/38.yaml
- ci/39.yaml
- ci/310.yaml
- ci/38-MIN.yaml
- ci/38-BASE.yaml
- ci/39-BASE.yaml
- ci/310-BASE.yaml
- ci/310-DEV.yaml
- ci/310-DEV_shapely_dev.yaml
include:
- environment-file: ci/310.yaml
- environment-file: ci/310-BASE.yaml
os: macos-latest
- environment-file: ci/310.yaml
- environment-file: ci/310-BASE.yaml
os: windows-latest
fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If you are new to `splot` and `PySAL` you will best get started with our [docume

### Installing dependencies

`splot` is compatible with `Python` 3.8+ and depends on `geopandas` 0.4.0 or later and `matplotlib` 2.2.2 or later.
`splot` is compatible with `Python` 3.8+ and depends on `geopandas` 0.9.0 or later and `matplotlib` 3.3.3 or later.

splot also uses

Expand Down
3 changes: 2 additions & 1 deletion ci/310.yaml → ci/310-BASE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ dependencies:
- esda
- geopandas
- giddy
# - ipywidgets
- ipywidgets
- libpysal
- mapclassify
- matplotlib
- numpy
- packaging
- pip
- seaborn>=0.11.0
- spreg
Expand Down
3 changes: 2 additions & 1 deletion ci/310-DEV.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ dependencies:
- pytest-cov
# required
- bokeh
- geopandas>=0.4.0
- geopandas
- ipywidgets
- matplotlib
- numpy
- packaging
- pip
- seaborn>=0.11.0
# formatting
Expand Down
3 changes: 2 additions & 1 deletion ci/310-DEV_shapely_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ dependencies:
- ipywidgets
- matplotlib
- numpy
- packaging
- pip
- seaborn>=0.11.0
- seaborn
- shapely>=2.0b1
# formatting
- black
Expand Down
5 changes: 3 additions & 2 deletions ci/38.yaml → ci/38-BASE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ dependencies:
# required
- bokeh
- esda
- geopandas>=0.4.0
- geopandas>=0.9.0
- giddy
- ipywidgets
- libpysal
- mapclassify
- matplotlib
- matplotlib>=3.3.3
- numpy
- packaging
- pip
- seaborn>=0.11.0
- spreg
Expand Down
27 changes: 27 additions & 0 deletions ci/38-MIN.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: test
channels:
- conda-forge
dependencies:
- python=3.8
# testing
- codecov
- pytest
- pytest-cov
# required
- bokeh
- esda
- geopandas==0.9.0
- giddy
- libpysal
- mapclassify
- matplotlib==3.3.3
- numpy
- packaging
- pip
- seaborn==0.11.0
- spreg
# formatting
- black
- flake8
- isort
- pyflakes
3 changes: 2 additions & 1 deletion ci/39.yaml → ci/39-BASE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ dependencies:
# required
- bokeh
- esda
- geopandas>=0.4.0
- geopandas
- giddy
- ipywidgets
- libpysal
- mapclassify
- matplotlib
- numpy
- packaging
- pip
- seaborn>=0.11.0
- spreg
Expand Down
2 changes: 1 addition & 1 deletion doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Installing dependencies
-----------------------

`splot` is compatible with Python `3.8+` and
depends on GeoPandas 0.4.0 or later and matplotlib 2.2.2 or later.
depends on GeoPandas 0.9.0 or later and matplotlib 3.3.3 or later.
Please make sure that you are operating in a Python 3 environment.

splot also uses
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
esda
geopandas>=0.4.0
geopandas>=0.9.0
giddy
libpysal
mapclassify
matplotlib
matplotlib>=3.3.3
numpy
packaging
seaborn>=0.11.0
spreg
4 changes: 2 additions & 2 deletions splot/_viz_esda_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def moran_scatterplot(
elif isinstance(moran, Moran_BV):
if p is not None:
warnings.warn(
"`p` is only used for plotting `esda.moran.Moran_Local`\n"
"or `Moran_Local_BV` objects"
"`p` is only used for plotting `esda.moran.Moran_Local` "
"or `Moran_Local_BV` objects."
)
fig, ax = _moran_bv_scatterplot(
moran_bv=moran,
Expand Down
23 changes: 21 additions & 2 deletions splot/_viz_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import mapclassify as classify
import matplotlib
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
from packaging.version import Version

# isolate MPL version - GH#162
MPL_36 = Version(matplotlib.__version__) >= Version("3.6")
if MPL_36:
from matplotlib import colormaps as cm
else:
import matplotlib.cm as cm
import matplotlib.pyplot as plt


"""
Utility functions for lightweight visualizations in splot
Expand Down Expand Up @@ -301,9 +310,18 @@ def shift_colormap( # noqa E302
cdict["blue"].append((si, b, b))
cdict["alpha"].append((si, a, a))

"""
new_cmap = mpl.colors.LinearSegmentedColormap(name, cdict)
plt.register_cmap(cmap=new_cmap)
return new_cmap
"""

new_cmap = mpl.colors.LinearSegmentedColormap(name, cdict)
if MPL_36:
cm.register(new_cmap)
else:
plt.register_cmap(cmap=new_cmap)
return new_cmap


# Utility #2 - truncate colorcap in order to grab only positive or negative portion
Expand All @@ -329,6 +347,7 @@ def truncate_colormap(cmap, minval=0.0, maxval=1.0, n=100):
-------
new_cmap : A new colormap that has been shifted.
"""

if isinstance(cmap, str):
cmap = cm.get_cmap(cmap)

Expand Down
11 changes: 10 additions & 1 deletion splot/_viz_value_by_alpha_mpl.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import collections.abc

import matplotlib.cm as cm
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors, patches
from packaging.version import Version

from ._viz_utils import _classifiers, format_legend

# isolate MPL version - GH#162
MPL_36 = Version(matplotlib.__version__) >= Version("3.6")
if MPL_36:
from matplotlib import colormaps as cm
else:
import matplotlib.cm as cm


"""
Creating Maps with splot
* Value-by-Alpha maps
Expand Down
71 changes: 40 additions & 31 deletions splot/tests/test_viz_esda_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import libpysal as lp
import matplotlib.pyplot as plt
import numpy as np
import pytest
from esda.moran import Moran, Moran_BV, Moran_BV_matrix, Moran_Local, Moran_Local_BV
from libpysal import examples
from libpysal.weights.contiguity import Queen
from pytest import raises, warns

from splot._viz_esda_mpl import (
_moran_bv_scatterplot,
Expand Down Expand Up @@ -51,18 +51,25 @@ def test_moran_scatterplot():
y = gdf["Donatns"].values
w = Queen.from_dataframe(gdf)
w.transform = "r"

# Calculate `esda.moran` Objects
moran = Moran(y, w)
moran_bv = Moran_BV(y, x, w)
moran_loc = Moran_Local(y, w)
moran_loc_bv = Moran_Local_BV(y, x, w)

# try with p value so points are colored or warnings apply
fig, _ = moran_scatterplot(moran, p=0.05, aspect_equal=False)
plt.close(fig)
with pytest.warns(UserWarning, match="`p` is only used for plotting"):
fig, _ = moran_scatterplot(moran, p=0.05, aspect_equal=False)
plt.close(fig)

fig, _ = moran_scatterplot(moran_loc, p=0.05)
plt.close(fig)
fig, _ = moran_scatterplot(moran_bv, p=0.05)
plt.close(fig)

with pytest.warns(UserWarning, match="`p` is only used for plotting"):
fig, _ = moran_scatterplot(moran_bv, p=0.05)
plt.close(fig)

fig, _ = moran_scatterplot(moran_loc_bv, p=0.05)
plt.close(fig)

Expand Down Expand Up @@ -211,8 +218,8 @@ def test_moran_loc_scatterplot():
)
plt.close(fig)

raises(ValueError, _moran_loc_scatterplot, moran_bv, p=0.5)
warns(
pytest.raises(ValueError, _moran_loc_scatterplot, moran_bv, p=0.5)
pytest.warns(
UserWarning,
_moran_loc_scatterplot,
moran_loc,
Expand Down Expand Up @@ -253,30 +260,32 @@ def test_plot_local_autocorrelation():
plt.close(fig)

# also test with quadrant and mask
fig, _ = plot_local_autocorrelation(
moran_loc,
df,
"HOVAL",
p=0.05,
region_column="POLYID",
aspect_equal=False,
mask=["1", "2", "3"],
quadrant=1,
)
plt.close(fig)
with pytest.warns(UserWarning, match="Values in `mask` are not the same dtype"):
fig, _ = plot_local_autocorrelation(
moran_loc,
df,
"HOVAL",
p=0.05,
region_column="POLYID",
aspect_equal=False,
mask=["1", "2", "3"],
quadrant=1,
)
plt.close(fig)

# also test with quadrant and mask
raises(
ValueError,
plot_local_autocorrelation,
moran_loc,
df,
"HOVAL",
p=0.05,
region_column="POLYID",
mask=["100", "200", "300"],
quadrant=1,
)
with pytest.warns(UserWarning, match="Values in `mask` are not the same dtype"):
pytest.raises(
ValueError,
plot_local_autocorrelation,
moran_loc,
df,
"HOVAL",
p=0.05,
region_column="POLYID",
mask=["100", "200", "300"],
quadrant=1,
)


def test_moran_loc_bv_scatterplot():
Expand All @@ -296,8 +305,8 @@ def test_moran_loc_bv_scatterplot():
fig, _ = _moran_loc_bv_scatterplot(moran_loc_bv, p=0.05, aspect_equal=False)
plt.close(fig)

raises(ValueError, _moran_loc_bv_scatterplot, moran_loc, p=0.5)
warns(
pytest.raises(ValueError, _moran_loc_bv_scatterplot, moran_loc, p=0.5)
pytest.warns(
UserWarning,
_moran_loc_bv_scatterplot,
moran_loc_bv,
Expand Down
3 changes: 1 addition & 2 deletions splot/tests/test_viz_giddy_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
from libpysal import examples
from libpysal.weights.contiguity import Queen
from pytest import raises

try:
import ipywidgets # noqa F401
Expand Down Expand Up @@ -64,7 +63,7 @@ def test_dynamic_lisa_rose():
fig3, _ = dynamic_lisa_rose(rose, c="r")
plt.close(fig3)

raises(ValueError, dynamic_lisa_rose, rose, attribute=y1, color="blue")
pytest.raises(ValueError, dynamic_lisa_rose, rose, attribute=y1, color="blue")


def test_dynamic_lisa_vectors():
Expand Down
Loading

0 comments on commit 7750929

Please sign in to comment.