developmentseed / developmentseed/lonboard

[BUG] Map.fly_to raises if you pass a numpy.int64 for zoom

Open
#1,046 7 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
964
Forks
54
Avg merge
5m
Merged PRs (30d)
1

Description

## Context

I called `Map.fly_to` and passed a value for `zoom` that was a `numpy.int64`.

## Resulting behaviour, error message or logs

A type error got raised because of the `numpy.int64`. The type checking in the `fly_to` is overly restrictive and explicitly checks for a normal `int` or `float`:

```python
if not isinstance(zoom, (int, float)):
raise TypeError(f"Expected zoom to be an int or float, got {type(zoom)}")
```

I recommend instead trying to cast the value for zoom (and latitude and longitude) to floats and only raising if that fails.

## Environment

- OS: Windows 11
- Browser: Firefox
- Lonboard Version: 0.12.1 (though I see it's still present in 0.13.0)

## Steps to reproduce the bug

```python
import geopandas as gpd
import numpy as np
from shapely.geometry import Point

import lonboard

d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
gdf = gpd.GeoDataFrame(d, crs="EPSG:4326")
layer = lonboard.ScatterplotLayer.from_geopandas(gdf)
map_ = lonboard.Map(layers=[layer])

map_.fly_to(longitude=0, latitude=0, zoom=np.int64(2))
```


Thank you for all of your efforts on lonboard. This library has been extremely helpful for a project that I'm currently working on that involves plotting large shapefiles.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start from the Map.fly_to implementation and reproduce the supplied example with numpy.int64(2). Check how zoom, latitude, and longitude are validated; done means numpy numeric values are accepted while values that cannot be converted still raise an appropriate error.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.