deck.gl
deck.gl copied to clipboard
pydeck: Layers fail on data columns names with hyphens or whitespace
The code sample below fails because of lng-new, which the JS expression parser in @deck.gl/json treats as datum.lng - datum.new.
import pydeck as pdk
import pandas as pd
UK_ACCIDENTS_DATA = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv'
df = pd.read_csv(UK_ACCIDENTS_DATA)
df['lng-new'] = df['lng']
df.head()
layer = pdk.Layer(
'HexagonLayer',
UK_ACCIDENTS_DATA,
get_position=['lng-new', 'lat'],
auto_highlight=True,
elevation_scale=50,
pickable=True,
elevation_range=[0, 3000],
extruded=True,
coverage=1)
# Set the viewport location
view_state = pdk.ViewState(
longitude=-1.415,
latitude=52.2323,
zoom=6,
min_zoom=5,
max_zoom=15,
pitch=40.5,
bearing=-27.36)
# Combined all of it and render a viewport
r = pdk.Deck(layers=[layer], initial_view_state=view_state)
r.show()
It's possible that pydeck should sanitize column names in a data frame before passing them to @deck.gl/json or warn if a column name contains a JS arithmetic operator or whitespace. Alternately it could make sense to change this behavior within @deck.gl/json.
This still doesn't seem fixed. Just took me a couple hours of testing to find a space in a column name (in my case used like:
Layer(..., get_text="Something With Spaces", ..)
This failed until I renamed the column:
test_data = test_data.rename(columns={"Something With Spaces": "NoSpaces"})
Layer(..., get_text="NoSpaces", ..)