Skip to content

Commit

Permalink
BUG: Ignore NaN in setting mn and mx (#877) (#878)
Browse files Browse the repository at this point in the history
* ignore nan in setting mn and mx

* test if vmin vmax set correctly for array with NaN

* test compatible with older versions

* reference to issue and shorter assert in test
  • Loading branch information
martinfleis authored and jdmcbr committed Dec 12, 2018
1 parent 14dee6a commit 41ea283
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions geopandas/plotting.py
Expand Up @@ -453,8 +453,8 @@ def plot_dataframe(df, column=None, cmap=None, color=None, ax=None,
for i in range(len(binedges)-1)]
values = np.array(binning.yb)

mn = values.min() if vmin is None else vmin
mx = values.max() if vmax is None else vmax
mn = values[~np.isnan(values)].min() if vmin is None else vmin
mx = values[~np.isnan(values)].max() if vmax is None else vmax

geom_types = df.geometry.type
poly_idx = np.asarray((geom_types == 'Polygon')
Expand Down
10 changes: 10 additions & 0 deletions geopandas/tests/test_plotting.py
Expand Up @@ -261,6 +261,10 @@ def setup_method(self):
self.df2 = GeoDataFrame({'geometry': [multipoly1, multipoly2],
'values': [0, 1]})

t3 = Polygon([(2, 0), (3, 0), (3, 1)])
df_nan = GeoDataFrame({'geometry': t3, 'values': [np.nan]})
self.df3 = self.df.append(df_nan)

def test_single_color(self):

ax = self.polys.plot(color='green')
Expand Down Expand Up @@ -290,6 +294,12 @@ def test_vmin_vmax(self):
actual_colors = ax.collections[0].get_facecolors()
np.testing.assert_array_equal(actual_colors[0], actual_colors[1])

# vmin vmax set correctly for array with NaN (GitHub issue 877)
ax = self.df3.plot(column='values')
actual_colors = ax.collections[0].get_facecolors()
assert np.any(np.not_equal(actual_colors[0], actual_colors[1]))


def test_style_kwargs(self):

# facecolor overrides default cmap when color is not set
Expand Down

0 comments on commit 41ea283

Please sign in to comment.