Skip to content

Commit d3f1080

Browse files
author
knaaptime
committed
move cmap check
1 parent ee3d76a commit d3f1080

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

geosnap/visualize/interactive.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ def _dexplore(
236236
nan_color = np.append(nan_color, [255])
237237
else:
238238
raise ValueError("nan_color must be an iterable of 3 or 4 values")
239-
if cmap not in colormaps:
240-
raise ValueError(
241-
f"`cmap` must be one of {list(colormaps.keys())} but {cmap} was passed"
242-
)
239+
243240
# only polygons have z
244241
if ["Polygon", "MultiPolygon"] in gdf.geometry.geom_type.unique():
245242
layer_kwargs["get_elevation"] = elevation
@@ -260,6 +257,10 @@ def _dexplore(
260257
raise ValueError(f"the designated column {column} is not in the dataframe")
261258
if gdf[column].dtype in ["O", "category"]:
262259
categorical = True
260+
if cmap is not None and cmap not in colormaps:
261+
raise ValueError(
262+
f"`cmap` must be one of {list(colormaps.keys())} but {cmap} was passed"
263+
)
263264
if cmap is None:
264265
cmap = "Set1" if categorical else "viridis"
265266
if categorical:
@@ -312,7 +313,6 @@ def _get_categorical_cmap(categories, cmap, nan_color, alpha):
312313
) from e
313314

314315
cat_codes = pd.Series(pd.Categorical(categories).codes, dtype="category")
315-
BOTTOM = False if -1 in cat_codes else True
316316

317317
# nans are encoded as -1 OR largest category depending on input type
318318
# re-encode to always be last category
@@ -323,10 +323,8 @@ def _get_categorical_cmap(categories, cmap, nan_color, alpha):
323323

324324
colors = colormaps[cmap].resampled(n_cats)(list(range(n_cats)), alpha)
325325
colors = (np.array(colors) * 255).astype(int)
326-
if BOTTOM:
327-
colors = np.vstack([colors, nan_color])
328-
else:
329-
colors = np.vstack([nan_color, colors])
326+
colors = np.vstack([colors, nan_color])
327+
330328

331329
n_colors = colors.shape[0]
332330

0 commit comments

Comments
 (0)