You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected results are for apply_categorical_cmap() to return a color object that I could pass to PathLayer.from_geopandas().
In version 0.9.2 the apply_categorical_cmap() function worked with the following call: apply_categorical_cmap(df[attribute_to_map], cmap) where df[attribute_to_map] is a categorical data column in a pandas dataframe, and cmap is a custom defined dictionary:
cmap = {
"<20": colorbrewer.sequential.YlGnBu_8.colors[0],
"20 to 30": colorbrewer.sequential.YlGnBu_8.colors[1],
"30 to 40": colorbrewer.sequential.YlGnBu_8.colors[2],
"40 to 50": colorbrewer.sequential.YlGnBu_8.colors[3],
"50 to 60": colorbrewer.sequential.YlGnBu_8.colors[4],
"60 to 70": colorbrewer.sequential.YlGnBu_8.colors[5],
"70 to 80": colorbrewer.sequential.YlGnBu_8.colors[6],
">80": colorbrewer.sequential.YlGnBu_8.colors[7],
}
The keys of this cmap dictionary are the labels of the categorical bins, created using pd.cut(). The values are RGB colors from the colorbrewer module in paletteable.
Resulting behaviour, error message or logs
Describe what happened:
An error is thrown:
File \.venv\Lib\site-packages\lonboard\colormap.py:193, in apply_categorical_cmap(values, cmap, alpha)
[190](/.venv/Lib/site-packages/lonboard/colormap.py:190) import pandas as pd
[192](/.venv/Lib/site-packages/lonboard/colormap.py:192) if isinstance(values, pd.Series):
--> [193](/.venv/Lib/site-packages/lonboard/colormap.py:193) values = Array.from_numpy(values)
[194](/.venv/Lib/site-packages/lonboard/colormap.py:194) except ImportError:
[195](/.venv/Lib/site-packages/lonboard/colormap.py:195) pass
ValueError: Unsupported data type object
Include relevant screenshots, error messages, and logs:
Environment
OS: Windows 11
Browser: VSCode
Python 3.12.3
Lonboard Version: 0.10.3
Steps to reproduce the bug
Describe the actions that led you to encounter the bug. Example:
imported lonboard into a new notebook
used pandas to bin a continuous variable into categories
created an instance of a map
added a path layer of the binned categorical data, with apply_categorical_cmap as the get_color argument
The text was updated successfully, but these errors were encountered:
Casting the dataframe column to a pyarrow array when passing it to the apply_categorical_cmap function makes it work. Going to leave this open in case it's unintended for that to have broken in between versions, but wanted to note a workaround.
Updated code is just: apply_categorical_cmap(pa.array(df[attribute_to_map]), cmap).
Context
What results were you expecting?
Expected results are for
apply_categorical_cmap()
to return a color object that I could pass toPathLayer.from_geopandas()
.In version 0.9.2 the
apply_categorical_cmap()
function worked with the following call:apply_categorical_cmap(df[attribute_to_map], cmap)
wheredf[attribute_to_map]
is a categorical data column in a pandas dataframe, andcmap
is a custom defined dictionary:The keys of this
cmap
dictionary are the labels of the categorical bins, created usingpd.cut()
. The values are RGB colors from the colorbrewer module inpaletteable
.Resulting behaviour, error message or logs
Describe what happened:
An error is thrown:
Include relevant screenshots, error messages, and logs:
Environment
Steps to reproduce the bug
Describe the actions that led you to encounter the bug. Example:
apply_categorical_cmap
as theget_color
argumentThe text was updated successfully, but these errors were encountered: