Skip to content

Commit

Permalink
chore(plotlymap): improvement file handling (#982)
Browse files Browse the repository at this point in the history
* chore(plotlymap): improvement file handling

Signed-off-by: slowy07 <[email protected]>

* fix(revert): change `data.copy()` to `data`

Signed-off-by: slowy07 <[email protected]>

---------

Signed-off-by: slowy07 <[email protected]>
  • Loading branch information
slowy07 authored Nov 17, 2024
1 parent 05105fa commit 84e6391
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion leafmap/plotlymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,23 @@ def add_heatmap(
"""

if isinstance(data, str):
df = pd.read_csv(data)
try:
df = pd.read_csv(data)
except FileNotFoundError:
raise FileNotFoundError(f"file path {data} not found")
except Exception as other_error:
raise ValueError(f"failed load data from {data}: {other_error}")
elif isinstance(data, pd.DataFrame):
df = data
else:
raise ValueError("data must be a DataFrame or a file path.")

for column_data in [latitude, longitude, z]:
if column_data not in df.columns:
raise KeyError(
f"column {column_data} not found, available columns {', '.join(df.columns)}"
)

heatmap = go.Densitymapbox(
lat=df[latitude],
lon=df[longitude],
Expand Down

0 comments on commit 84e6391

Please sign in to comment.