Skip to content

Commit 5f988a6

Browse files
committed
Fix geopandas import
1 parent 5fa9d9f commit 5f988a6

22 files changed

+272
-4760
lines changed

maplibre/__future__/controls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from enum import Enum
44

5-
from ..controls import Control
6-
75
from pydantic import Field
86

7+
from ..controls import Control
8+
99

1010
class GeocoderType(Enum):
1111
MAPTILTER = "maptiler"

maplibre/__future__/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional, Union
22

33
import geopandas as gpd
4+
from pydantic import BaseModel
45

56
# from geopandas import read_file
67
from maplibre.sources import GeoJSONSource
7-
from pydantic import BaseModel
88

99

1010
class DataSet(BaseModel):

maplibre/__future__/ipywidget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from pathlib import Path
44

5+
from ..ipywidget import MapWidget as BaseWidget
56
from .controls import GeocoderType
67

7-
from ..ipywidget import MapWidget as BaseWidget
88

99
class MapWidget(BaseWidget):
1010
_geocoder_type = GeocoderType.MAPTILTER

maplibre/__future__/pandas_ext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import geopandas as gpd
2-
import maplibre.express as mx
32
import pandas as pd
43

4+
import maplibre.express as mx
5+
56
from ..sources import GeoJSONSource, SimpleFeatures
67

78

maplibre/_constants.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
_points = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/scatterplot/manhattan.json"
77
_geojson = "https://docs.mapbox.com/mapbox-gl-js/assets/indoor-3d-map.geojson"
88
_urban_areas = "https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_urban_areas.geojson"
9-
_highway_lines = (
10-
"https://github.com/visgl/deck.gl-data/raw/master/examples/highway/roads.json"
11-
)
9+
_highway_lines = "https://github.com/visgl/deck.gl-data/raw/master/examples/highway/roads.json"
1210

13-
_airports = (
14-
"https://github.com/visgl/deck.gl-data/raw/master/examples/line/airports.json"
15-
)
11+
_airports = "https://github.com/visgl/deck.gl-data/raw/master/examples/line/airports.json"
1612
_flights = "https://github.com/visgl/deck.gl-data/raw/master/examples/line/heathrow-flights.json"

maplibre/anywidget.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ class MapWidget(AnyWidget, Map):
3838
_css = Path(__file__).parent / "srcjs" / "maplibre.anywidget.css"
3939

4040
_use_message_queue = True
41-
_rendered = traitlets.Bool(False).tag(config=True).tag(sync=True)
41+
# _rendered = traitlets.Bool(False).tag(config=True).tag(sync=True)
42+
load = traitlets.Bool(False).tag(sync=True)
4243
map_options = traitlets.Dict().tag(sync=True)
4344
calls = traitlets.List().tag(sync=True)
45+
msg = traitlets.List().tag(sync=True)
4446
height = traitlets.Union([traitlets.Int(), traitlets.Unicode()]).tag(sync=True)
4547

4648
# Interactions Map
@@ -63,8 +65,8 @@ def __init__(
6365
height: int | str = 400,
6466
**kwargs,
6567
) -> None:
66-
self._rendered = False
67-
self.calls = []
68+
# self._rendered = False
69+
# self.calls = []
6870
AnyWidget.__init__(self, height=height, **kwargs)
6971
Map.__init__(self, map_options, sources, layers, controls, **kwargs)
7072

@@ -76,15 +78,33 @@ def _validate_height(self, proposal):
7678

7779
return height
7880

81+
"""
7982
@traitlets.observe("_rendered")
8083
def _on_rendered(self, change):
8184
self.send({"calls": self._message_queue, "msg": "init"})
8285
self._message_queue = []
86+
"""
8387

88+
"""
8489
def use_message_queue(self, value: bool = True) -> None:
8590
self._use_message_queue = value
91+
"""
92+
93+
# @traitlets.observe("load")
94+
# def _(self, change) -> None:
95+
# self.send({"calls": self.calls, "msg": "observe load"})
8696

8797
def add_call(self, method_name: str, *args) -> None:
98+
call = [method_name, args]
99+
if self.load:
100+
# self.send({"calls": [call], "msg": "custom call"})
101+
self.msg = call
102+
return
103+
104+
# Initial calls
105+
self.calls = self.calls + [call]
106+
107+
def _add_call(self, method_name: str, *args) -> None:
88108
call = [method_name, args]
89109
if not self._rendered:
90110
if not self._use_message_queue:

maplibre/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class Config(BaseModel):
2626

2727
maptiler_api_key_env_var: Optional[str] = "MAPTILER_API_KEY"
2828

29-
layer_types: Optional[dict] = dict(
30-
Polygon="fill", LineString="line", Point="circle"
31-
)
29+
layer_types: Optional[dict] = dict(Polygon="fill", LineString="line", Point="circle")
3230

3331
@property
3432
def maptiler_api_key(self) -> str:

maplibre/experimental.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55
from typing import Literal
66

77
from geopandas import GeoDataFrame
8-
from pydantic import (
9-
BaseModel,
10-
ConfigDict,
11-
Field,
12-
computed_field,
13-
field_validator,
14-
model_serializer,
15-
)
8+
from pydantic import BaseModel, ConfigDict, Field, computed_field, field_validator, model_serializer
169

1710
from maplibre import Layer, LayerType
1811
from maplibre.utils import geopandas_to_geojson

maplibre/express.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,19 @@ def color_quantile(
7777
probs: list = [0.1, 0.25, 0.5, 0.75],
7878
cmap: str = config.cmap,
7979
) -> Self:
80-
expr = color_quantile_step_expr(
81-
column, probs, values=self.sf.data[column], cmap=cmap
82-
)
80+
expr = color_quantile_step_expr(column, probs, values=self.sf.data[column], cmap=cmap)
8381
self._set_paint_property("color", expr)
8482
return self
8583

86-
def color_bin(
87-
self, column: str, stops: list = None, n: int = None, cmap=config.cmap
88-
) -> Self:
84+
def color_bin(self, column: str, stops: list = None, n: int = None, cmap=config.cmap) -> Self:
8985
if stops is None and n is None:
9086
pass
9187

9288
expr = color_step_expr(column, stops, cmap)
9389
self._set_paint_property("color", expr)
9490
return self
9591

96-
def interpolate_color(
97-
self, column: str, stops=None, colors=("yellow", "red")
98-
) -> Self:
92+
def interpolate_color(self, column: str, stops=None, colors=("yellow", "red")) -> Self:
9993
stops = stops or [f(self.sf.data[column]) for f in [min, max]]
10094
expr = interpolate(column, stops, colors)
10195
self._set_paint_property("color", expr)
@@ -164,9 +158,7 @@ def fill_extrusion(
164158
**kwargs,
165159
) -> SimpleLayer:
166160
if "paint" not in kwargs:
167-
kwargs["paint"] = config.paint_props[
168-
LayerType.FILL_EXTRUSION.value.replace("-", "_")
169-
]
161+
kwargs["paint"] = config.paint_props[LayerType.FILL_EXTRUSION.value.replace("-", "_")]
170162

171163
if fill_extrusion_base is not None:
172164
kwargs["paint"]["fill-extrusion-base"] = fill_extrusion_base
@@ -190,9 +182,7 @@ def fill_line_circle(source_id: str, colors: list = None) -> list:
190182
type=LayerType.FILL,
191183
source=source_id,
192184
filter=geometry_type_filter(GeometryType.POLYGON),
193-
).set_paint_props(
194-
fill_color=fill_color, fill_outline_color=config.fill_outline_color
195-
)
185+
).set_paint_props(fill_color=fill_color, fill_outline_color=config.fill_outline_color)
196186

197187
line_layer = Layer(
198188
type=LayerType.LINE,

maplibre/expressions.py

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,20 @@ def geometry_type_filter(geom_type: GeometryType | str) -> list:
2727
return ["==", get_geometry_type(), GeometryType(geom_type).value]
2828

2929

30-
def interpolate(
31-
property: str | list, stops: list, outputs: list, type: list = ["linear"]
32-
) -> list:
30+
def interpolate(property: str | list, stops: list, outputs: list, type: list = ["linear"]) -> list:
3331
assert len(stops) == len(outputs)
3432
return [
3533
"interpolate",
3634
type,
3735
get_column(property) if isinstance(property, str) else property,
38-
] + list(
39-
itertools.chain.from_iterable(
40-
[[stop, output] for stop, output in zip(stops, outputs)]
41-
)
42-
)
36+
] + list(itertools.chain.from_iterable([[stop, output] for stop, output in zip(stops, outputs)]))
4337

4438

4539
def match_expr(column: str, categories: list, outputs: list[T], fallback: T) -> list:
4640
assert len(categories) == len(outputs)
4741
return (
4842
["match", get_column(column)]
49-
+ list(
50-
itertools.chain.from_iterable(
51-
[[category, output] for category, output in zip(categories, outputs)]
52-
)
53-
)
43+
+ list(itertools.chain.from_iterable([[category, output] for category, output in zip(categories, outputs)]))
5444
+ [fallback]
5545
)
5646

@@ -70,18 +60,12 @@ def step_expr(
7060
"step",
7161
get_column(property) if isinstance(property, str) else property,
7262
]
73-
+ list(
74-
itertools.chain.from_iterable(
75-
[[output, stop] for output, stop in zip(outputs, stops)]
76-
)
77-
)
63+
+ list(itertools.chain.from_iterable([[output, stop] for output, stop in zip(outputs, stops)]))
7864
+ [fallback]
7965
)
8066

8167

82-
def quantile_step_expr(
83-
column: str, probs: list, outputs: list[T], fallback: T, values: list
84-
) -> list:
68+
def quantile_step_expr(column: str, probs: list, outputs: list[T], fallback: T, values: list) -> list:
8569
assert len(probs) == len(outputs)
8670
try:
8771
import numpy as np
@@ -98,14 +82,10 @@ def quantile_step_expr(
9882
# -----
9983

10084

101-
def color_quantile_step_expr(
102-
column: str, probs: list, values: Any, cmap="viridis"
103-
) -> list:
85+
def color_quantile_step_expr(column: str, probs: list, values: Any, cmap="viridis") -> list:
10486
n = len(probs)
10587
colors = color_brewer(cmap, n + 1)
106-
return quantile_step_expr(
107-
column, probs, outputs=colors[0:n], fallback=colors[-1], values=values
108-
)
88+
return quantile_step_expr(column, probs, outputs=colors[0:n], fallback=colors[-1], values=values)
10989

11090

11191
def color_step_expr(column: str, stops: list, cmap="viridis") -> list:
@@ -143,8 +123,6 @@ def filter_expr(column: str, operator: str, value: Any) -> list:
143123
return [operator, get_column(column), value]
144124

145125

146-
def range_filter(
147-
column, values: tuple | list, operators: tuple | list = (">=", "<=")
148-
) -> list:
126+
def range_filter(column, values: tuple | list, operators: tuple | list = (">=", "<=")) -> list:
149127
assert len(values) == len(operators) == 2
150128
return ["all"] + [[operators[i], get_column(column), values[i]] for i in range(2)]

0 commit comments

Comments
 (0)