Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geocoding 2.0 #304

Merged
merged 79 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
173d618
Put parents into regions dataframe and geodataframe
IKupriyanov-HORIS Sep 11, 2020
c8f8d1b
Implementing parents in regions_builder.
IKupriyanov-HORIS Sep 14, 2020
1fccca9
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Sep 14, 2020
6fef609
WIP: parents
IKupriyanov-HORIS Sep 15, 2020
9b5ae98
Fix tests, sync protocol with server
IKupriyanov-HORIS Sep 15, 2020
38f1db7
Fix more tests
IKupriyanov-HORIS Sep 16, 2020
54b4457
Fix more tests
IKupriyanov-HORIS Sep 25, 2020
299b6aa
New server IP in demo
IKupriyanov-HORIS Sep 25, 2020
701f78c
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Oct 5, 2020
a37a3f5
WIP: answers in protocol
IKupriyanov-HORIS Oct 14, 2020
f6ca8a3
WIP: moving to Answers instead of flat list of GeocodedFeature
IKupriyanov-HORIS Oct 14, 2020
52e7c1f
WIP: link between request and response
IKupriyanov-HORIS Oct 15, 2020
be18cc5
Getting rid of a query string from Answer and GeocodedFeature
IKupriyanov-HORIS Oct 17, 2020
e8219a8
Remove query from Answer and GeocodedFeature
IKupriyanov-HORIS Oct 19, 2020
326550b
Fix assertion condition
IKupriyanov-HORIS Oct 20, 2020
f6fc7c8
Remove chunked requests, better docs for new API
IKupriyanov-HORIS Oct 20, 2020
cbc1745
WIP: scope
IKupriyanov-HORIS Oct 21, 2020
02aa0ba
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Oct 21, 2020
cca501d
Update example with counties
IKupriyanov-HORIS Oct 22, 2020
91b027a
Update example with counties
IKupriyanov-HORIS Oct 22, 2020
21ec386
Basic support for scope in the new geocoding API
IKupriyanov-HORIS Oct 22, 2020
6f99bbe
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Oct 23, 2020
60968ca
Default scope value to None
IKupriyanov-HORIS Oct 26, 2020
f44d979
Unit tests for new geocoding API
IKupriyanov-HORIS Oct 28, 2020
9ed17b0
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Oct 28, 2020
539ef98
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Oct 28, 2020
4345821
Request validation, tests
IKupriyanov-HORIS Oct 28, 2020
648eef7
Experiment with map and nbviewer
IKupriyanov-HORIS Oct 29, 2020
d492167
Experiment with map and nbviewer and stamen tiles
IKupriyanov-HORIS Oct 29, 2020
bc846fa
Better parents/scope support, more tests
IKupriyanov-HORIS Oct 30, 2020
dcfd17b
where(..., near=..., within=...)
IKupriyanov-HORIS Nov 2, 2020
41e0ce1
Better error handling
IKupriyanov-HORIS Nov 3, 2020
26804b4
Tests for not available features in new API
IKupriyanov-HORIS Nov 4, 2020
fbd7c50
Better error handling for where function (missing key, scope and othe…
IKupriyanov-HORIS Nov 5, 2020
c444036
map_join with multikeys
IKupriyanov-HORIS Nov 14, 2020
0e213d9
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Nov 14, 2020
f7f5df8
Single key data_join_on and map_join_on.
IKupriyanov-HORIS Nov 15, 2020
a31ca74
Multi key data_join_on and map_join_on.
IKupriyanov-HORIS Nov 16, 2020
1f69608
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Nov 23, 2020
08f250f
map_join with dups, but livemap fails with null values in data
IKupriyanov-HORIS Nov 24, 2020
71060c2
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Nov 25, 2020
6c5f57b
Handle null values in pie/bar
IKupriyanov-HORIS Nov 26, 2020
cec1bdc
LP-62
IKupriyanov-HORIS Nov 27, 2020
c5375fb
Better error message on using scope with parents
IKupriyanov-HORIS Dec 4, 2020
5a2569d
Better error message for invalid scope type, countries request suppor…
IKupriyanov-HORIS Dec 7, 2020
4926246
More tests for us-48
IKupriyanov-HORIS Dec 8, 2020
c7c72ba
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Dec 8, 2020
dc5a21f
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Dec 14, 2020
b0ba74f
WIP: changing public API
IKupriyanov-HORIS Dec 15, 2020
536ed25
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Dec 18, 2020
fe750f7
Support Geocoder as geom_xxx(map=...) parameter
IKupriyanov-HORIS Dec 21, 2020
c317a16
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Dec 21, 2020
7531be1
Code cleanup, more tests
IKupriyanov-HORIS Dec 22, 2020
425fef3
Copy not matched dups from map on map_join (fix for last cell in geop…
IKupriyanov-HORIS Dec 23, 2020
ed5f0ea
Use single entry parent for all names
IKupriyanov-HORIS Dec 23, 2020
371525a
Fix empty result for select all kind of request
IKupriyanov-HORIS Dec 24, 2020
481b90d
where -> scope, near -> closest_to, single entry scope, remove auto-c…
IKupriyanov-HORIS Jan 11, 2021
4f3e114
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Jan 11, 2021
5002f32
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Jan 11, 2021
d316cbe
Remove MapRegion from 'scope' type error message
IKupriyanov-HORIS Jan 13, 2021
bfe2d0b
scope can now be used with county and state. scope and country will c…
IKupriyanov-HORIS Jan 14, 2021
f1a3014
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Jan 18, 2021
e747a7e
Handle any Iterable types in parents functions (counties/states/count…
IKupriyanov-HORIS Jan 20, 2021
3915dba
Enable gzip for geocoding responses
IKupriyanov-HORIS Jan 21, 2021
d8b1fac
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Jan 21, 2021
93c7aaa
Update docs
IKupriyanov-HORIS Jan 21, 2021
f1e98cd
Update docs
IKupriyanov-HORIS Jan 21, 2021
4b4a9ba
Keep original query name for ambiguous result with allow_ambiguous flag
IKupriyanov-HORIS Jan 22, 2021
ffaaab8
Fix error message
IKupriyanov-HORIS Jan 22, 2021
50156ed
Remove method to_data_frame and interface CanToDataFrame
IKupriyanov-HORIS Jan 25, 2021
8131764
WIP: update geocoding.md
IKupriyanov-HORIS Jan 26, 2021
1917b39
WIP: update geocoding.md
IKupriyanov-HORIS Jan 26, 2021
a908666
Revert changes to builder.ipynb
IKupriyanov-HORIS Jan 26, 2021
ff331eb
WIP: update geocoding.md
IKupriyanov-HORIS Jan 26, 2021
b6fa9b4
Use geocoding level instead of 'request' for a column name, remove da…
IKupriyanov-HORIS Jan 28, 2021
851fa40
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Jan 28, 2021
83002eb
Support Geocoder in ggplot(data=...)
IKupriyanov-HORIS Jan 29, 2021
99bd3c3
Switch to the new geocoding server
IKupriyanov-HORIS Jan 29, 2021
a203c3b
Merge branch 'master' into geoservices-1.1.0
IKupriyanov-HORIS Jan 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Getting rid of a query string from Answer and GeocodedFeature
  • Loading branch information
IKupriyanov-HORIS committed Oct 17, 2020
commit be18cc52f4496d8c5c8581ffc6b7df14a5a4b5d3
4 changes: 2 additions & 2 deletions python-package/lets_plot/geo_data/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .gis.geocoding_service import GeocodingService
from .gis.geometry import GeoPoint
from .gis.request import RequestBuilder, RequestKind
from .gis.request import RequestBuilder, RequestKind, RegionQuery
from .gis.response import Response, SuccessResponse
from .regions import Regions, _raise_exception, _to_level_kind, _to_scope
from .regions_builder import RegionsBuilder
Expand Down Expand Up @@ -65,7 +65,7 @@ def regions_xy(lon, lat, level, within=None):
if not isinstance(response, SuccessResponse):
_raise_exception(response)

return Regions(response.level, response.answers, False)
return Regions(response.level, response.answers, [RegionQuery(request=str(lon) + ', ' + str(lat))], False)


def regions_builder(level=None, request=None, within=None, highlights=False) -> RegionsBuilder:
Expand Down
5 changes: 0 additions & 5 deletions python-package/lets_plot/geo_data/gis/geocoding_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,3 @@ def _execute(self, request: Request) -> Response:
raise ValueError(
'Geocoding server connection failure: {} {} ({})'.format(e.code, e.msg, e.filename)) from None

except Exception as e:
return ResponseBuilder() \
.set_status(Status.error) \
.set_message('Internal service exception: {}'.format(str(e))) \
.build()
12 changes: 6 additions & 6 deletions python-package/lets_plot/geo_data/gis/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def name_or_none(place: Optional['MapRegion']):


@staticmethod
def place(id: str, request: str, level_kind: LevelKind):
def place(id: str, request: Optional[str], level_kind: LevelKind):
assert_type(id, str)
assert_type(request, str)
assert_optional_type(request, str)
assert_type(level_kind, LevelKind)
return MapRegion(MapRegionKind.place, [id], request, level_kind)

Expand All @@ -99,9 +99,9 @@ def __init__(self, kind: MapRegionKind, values: List[str], request: Optional[str
self._level_kind: Optional[LevelKind] = level_kind
self._hash = hash((self.values, self.kind))

def request(self) -> str:
def request(self) -> Optional[str]:
assert self.kind == MapRegionKind.place, 'Invalid MapRegion kind. Expected \'place\', but was ' + str(self.kind)
assert_type(self._request, str)
assert_optional_type(self._request, str)
return self._request

def name(self) -> str:
Expand Down Expand Up @@ -164,8 +164,8 @@ def __ne__(self, o):
class RegionQuery:
def __init__(self,
request: Optional[str],
scope: Optional[MapRegion],
ambiguity_resolver: AmbiguityResolver,
scope: Optional[MapRegion] = None,
ambiguity_resolver: AmbiguityResolver = AmbiguityResolver.empty(),
country: Optional[MapRegion] = None,
state: Optional[MapRegion] = None,
county: Optional[MapRegion] = None
Expand Down
6 changes: 3 additions & 3 deletions python-package/lets_plot/geo_data/gis/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self, message: str):

class FeatureBuilder:
def __init__(self):
self.query: str = None
self.query: Optional[str] = None
self.id: Optional[str] = None
self.name: Optional[str] = None
self.highlights: Optional[List[str]] = None
Expand All @@ -134,8 +134,8 @@ def __init__(self):
self.total_namesake_count: Optional[int] = None
self.namesake_examples: List[Namesake] = []

def set_query(self, v: str) -> 'FeatureBuilder':
assert_type(v, str)
def set_query(self, v: Optional[str]) -> 'FeatureBuilder':
assert_optional_type(v, str)
self.query = v
return self

Expand Down
23 changes: 13 additions & 10 deletions python-package/lets_plot/geo_data/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ class Resolution(enum.Enum):
def contains_values(column):
return any(v is not None for v in column)

def select_not_empty_name(feature: GeocodedFeature) -> str:
return feature.name if feature.query is None or feature.query == '' else feature.query
def select_request(query: RegionQuery, answer: Answer, feature: GeocodedFeature) -> str:
return query.request if len(answer.features) <= 1 else feature.name


def zip_answers(queries, answers):
def zip_answers(queries: List, answers: List):
if len(queries) > 0:
return zip(queries, answers)
elif len(queries) == len(answers):
else:
return zip([None] * len(answers), answers)


Expand Down Expand Up @@ -101,7 +100,7 @@ def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery] = [])


class Regions(CanToDataFrame):
def __init__(self, level_kind: LevelKind, answers: List[Answer], highlights: bool = False, queries: List[RegionQuery] = []):
def __init__(self, level_kind: LevelKind, answers: List[Answer], queries: List[RegionQuery], highlights: bool = False):
assert_list_type(answers, Answer)
assert_list_type(queries, RegionQuery)
assert len(queries) == 0 or len(answers) == len(queries)
Expand Down Expand Up @@ -129,14 +128,18 @@ def __len__(self):
return len(self._geocoded_features)

def to_map_regions(self):
return [MapRegion.place(feature.id, feature.query, self._level_kind) for feature in self._geocoded_features]
regions: List[MapRegion] = []
for answer, query in zip_answers(self._answers, self._queries):
for feature in answer.features:
regions.append(MapRegion.place(feature.id, select_request(query, answer, feature), self._level_kind))
return regions

def as_list(self) -> List['Regions']:
if len(self._queries) == 0:
return [Regions(self._level_kind, [answer], self._highlights) for answer in self._answers]
return [Regions(self._level_kind, [answer], [RegionQuery(request=None)], self._highlights) for answer in self._answers]

assert len(self._queries) == len(self._answers)
return [Regions(self._level_kind, [answer], self._highlights, [query]) for query, answer in zip(self._queries, self._answers)]
return [Regions(self._level_kind, [answer], [query], self._highlights) for query, answer in zip(self._queries, self._answers)]


def unique_ids(self) -> List[str]:
Expand Down Expand Up @@ -275,7 +278,7 @@ def to_data_frame(self) -> DataFrame:
# for us-48 queries doesnt' count
for query, answer in zip_answers(self._queries, self._answers):
for feature in answer.features:
places.append_row(select_not_empty_name(feature), feature.name, query)
places.append_row(select_request(query, answer, feature), feature.name, query)

data = {**data, **places.build_dict()}

Expand Down
2 changes: 1 addition & 1 deletion python-package/lets_plot/geo_data/regions_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def build(self) -> Regions:
if not isinstance(response, SuccessResponse):
_raise_exception(response)

return Regions(response.level, response.answers, self._highlights, queries)
return Regions(response.level, response.answers, queries, self._highlights)

def _get_queries(self) -> List[RegionQuery]:
for overriding in self._overridings:
Expand Down
16 changes: 8 additions & 8 deletions python-package/lets_plot/geo_data/to_geo_data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pandas import DataFrame
from shapely.geometry import box

from lets_plot.geo_data import PlacesDataFrameBuilder, zip_answers, select_not_empty_name, DF_REQUEST, DF_FOUND_NAME, abstractmethod
from lets_plot.geo_data import PlacesDataFrameBuilder, zip_answers, select_request, DF_REQUEST, DF_FOUND_NAME, abstractmethod
from lets_plot.geo_data.gis.response import Answer, GeocodedFeature, GeoRect, Boundary, Multipolygon, Polygon, GeoPoint
from lets_plot.geo_data.gis.request import RegionQuery

Expand Down Expand Up @@ -40,15 +40,15 @@ def __init__(self):
self._lonmax: List[float] = []
self._latmax: List[float] = []

def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery] = []) -> DataFrame:
def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery]) -> DataFrame:
assert len(answers) == len(queries)
places = PlacesDataFrameBuilder()


for query, answer in zip_answers(queries, answers):
for feature in answer.features:
rects: List[GeoRect] = self._read_rect(feature)
for rect in rects:
places.append_row(request=select_not_empty_name(feature), found_name=feature.name, query=query)
places.append_row(request=select_request(query, answer, feature), found_name=feature.name, query=query)
self._lonmin.append(rect.min_lon)
self._latmin.append(rect.min_lat)
self._lonmax.append(rect.max_lon)
Expand Down Expand Up @@ -80,12 +80,12 @@ def __init__(self):
self._lons: List[float] = []
self._lats: List[float] = []

def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery] = []) -> DataFrame:
def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery]) -> DataFrame:
places = PlacesDataFrameBuilder()

for query, answer in zip_answers(queries, answers):
for feature in answer.features:
places.append_row(request=select_not_empty_name(feature), found_name=feature.name, query=query)
places.append_row(request=select_request(query, answer, feature), found_name=feature.name, query=query)
self._lons.append(feature.centroid.lon)
self._lats.append(feature.centroid.lat)

Expand All @@ -97,13 +97,13 @@ class BoundariesGeoDataFrame:
def __init__(self):
super().__init__()

def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery] = []) -> DataFrame:
def to_data_frame(self, answers: List[Answer], queries: List[RegionQuery]) -> DataFrame:
places = PlacesDataFrameBuilder()

geometry = []
for query, answer in zip_answers(queries, answers):
for feature in answer.features:
places.append_row(request=select_not_empty_name(feature), found_name=feature.name, query=query)
places.append_row(request=select_request(query, answer, feature), found_name=feature.name, query=query)
geometry.append(self._geo_parse_geometry(feature.boundary))

return _create_geo_data_frame(places.build_dict(), geometry=geometry)
Expand Down
16 changes: 15 additions & 1 deletion python-package/test/geo_data/geo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from lets_plot.geo_data import DF_ID, DF_REQUEST, DF_FOUND_NAME, DF_PARENT_COUNTY, DF_PARENT_STATE, DF_PARENT_COUNTRY
from lets_plot.geo_data.gis.geometry import Ring, Polygon, Multipolygon
from lets_plot.geo_data.gis.json_response import ResponseField, GeometryKind
from lets_plot.geo_data.gis.request import RegionQuery
from lets_plot.geo_data.gis.response import Answer, GeocodedFeature, FeatureBuilder, LevelKind, Status, GeoRect, GeoPoint, \
Response, SuccessResponse, AmbiguousResponse, ErrorResponse, ResponseBuilder
from lets_plot.geo_data.regions import Regions
Expand Down Expand Up @@ -98,7 +99,11 @@ def assert_found_names(df: DataFrame, names: List[str]):


def make_geocode_region(request: str, name: str, geo_object_id: str, highlights: List[str], level_kind: LevelKind = LevelKind.city) -> Regions:
return Regions(level_kind, [make_region(request, name, geo_object_id, highlights)])
return Regions(
level_kind=level_kind,
answers=[make_region(request, name, geo_object_id, highlights)],
queries=[RegionQuery(request=request)]
)


def make_region(request: str, name: str, geo_object_id: str, highlights: List[str]) -> Answer:
Expand Down Expand Up @@ -279,3 +284,12 @@ def assert_boundary(boundary: DataFrame, index: int, points: List[GJPoint], name
def assert_point(df: DataFrame, index: int, lon: float, lat: float):
assert lon == df[DF_LON][index]
assert lat == df[DF_LAT][index]

def feature_to_answer(feature: GeocodedFeature) -> Answer:
return Answer(feature.query, [feature])

def features_to_answers(features: List[GeocodedFeature]) -> List[Answer]:
return [Answer(feature.query, [feature]) for feature in features]

def features_to_queries(features: List[GeocodedFeature]) -> List[RegionQuery]:
return [RegionQuery(feature.query) for feature in features]
65 changes: 35 additions & 30 deletions python-package/test/geo_data/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
LOCATION_LIST_ERROR_MESSAGE, LOCATION_DATAFRAME_ERROR_MESSAGE
from lets_plot.geo_data.regions import _to_scope, _coerce_resolution, _ensure_is_list, Regions, DF_REQUEST, DF_ID, \
DF_FOUND_NAME
from .geo_data import make_geocode_region, make_region, make_success_response
from .geo_data import make_geocode_region, make_region, make_success_response, features_to_answers, features_to_queries

DATAFRAME_COLUMN_NAME = 'name'
DATAFRAME_NAME_LIST = ['usa', 'russia']
Expand Down Expand Up @@ -95,6 +95,8 @@ def test_regions_with_highlights(mock_geocoding):
None # progress_callback
)

FOO_FEATURE = FeatureBuilder().set_query('foo').set_name('fooname').set_id('fooid').build_geocoded()
BAR_FEATURE = FeatureBuilder().set_query('bar').set_name('barname').set_id('barid').build_geocoded()

FOO = Answer('foo', [FeatureBuilder().set_query('foo').set_name('fooname').set_id('fooid').build_geocoded()])
BAR = Answer('foo', [FeatureBuilder().set_query('foo').set_name('barname').set_id('barid').build_geocoded()])
Expand All @@ -112,11 +114,10 @@ def test_regions_with_highlights(mock_geocoding):

# single region
(Regions(
LEVEL_KIND,
[
FOO,
BAR
]),
level_kind=LEVEL_KIND,
queries=features_to_queries([FOO_FEATURE, BAR_FEATURE]),
answers=features_to_answers([FOO_FEATURE, BAR_FEATURE])
),
MapRegion.scope([feature_id(FOO), feature_id(BAR)])
),

Expand All @@ -132,8 +133,16 @@ def test_regions_with_highlights(mock_geocoding):

# list of regions
([
Regions(LEVEL_KIND, [FOO]),
Regions(LEVEL_KIND, [BAR])
Regions(
level_kind=LEVEL_KIND,
queries=features_to_queries([FOO_FEATURE]),
answers=features_to_answers([FOO_FEATURE])
),
Regions(
level_kind=LEVEL_KIND,
queries=features_to_queries([BAR_FEATURE]),
answers=features_to_answers([BAR_FEATURE]),
)
],

[
Expand All @@ -145,7 +154,11 @@ def test_regions_with_highlights(mock_geocoding):
# mix of strings and regions
([
'foo',
Regions(LEVEL_KIND, [BAR]),
Regions(
level_kind=LEVEL_KIND,
queries=features_to_queries([BAR_FEATURE]),
answers=features_to_answers([BAR_FEATURE])
)
],
[
MapRegion.with_name(FOO.query),
Expand All @@ -166,19 +179,17 @@ def test_to_parent_with_id():
def test_request_remove_duplicated_ids(mock_request):
try:
Regions(
LEVEL_KIND,
[
make_region(REQUEST, REGION_NAME, REGION_ID, REGION_HIGHLIGHTS),
make_region(REQUEST, REGION_NAME, REGION_ID, REGION_HIGHLIGHTS)
]
level_kind=LEVEL_KIND,
queries=features_to_queries([FOO_FEATURE, FOO_FEATURE]),
answers=features_to_answers([FOO_FEATURE, FOO_FEATURE])
).centroids()
except ValueError:
pass # response doesn't contain proper feature with ids - ignore

mock_request.assert_called_with(
ExplicitRequest(
requested_payload=[PayloadKind.centroids],
ids=[REGION_ID]
ids=[FOO_FEATURE.id]
)
)

Expand Down Expand Up @@ -231,23 +242,17 @@ def test_geocode_limit(mock_request):

@mock.patch.object(GeocodingService, 'do_request')
def test_reorder_for_centroids_should_happen(mock_request):
mock_request.return_value = make_success_response() \
.set_geocoded_features(
[
FeatureBuilder().set_id('2').set_query('New York').set_name('New York').set_centroid(GeoPoint(0, 0)).build_geocoded(),
FeatureBuilder().set_id('3').set_query('Las Vegas').set_name('Las Vegas').set_centroid(GeoPoint(0, 0)).build_geocoded(),
FeatureBuilder().set_id('1').set_query('Los Angeles').set_name('Los Angeles').set_centroid(GeoPoint(0, 0)).build_geocoded()
]
).build()
new_york = FeatureBuilder().set_id('2').set_query('New York').set_name('New York').set_centroid(GeoPoint(0, 0)).build_geocoded()
las_vegas = FeatureBuilder().set_id('3').set_query('Las Vegas').set_name('Las Vegas').set_centroid(GeoPoint(0, 0)).build_geocoded()

los_angeles = FeatureBuilder().set_id('1').set_query('Los Angeles').set_name('Los Angeles').set_centroid(
GeoPoint(0, 0)).build_geocoded()
mock_request.return_value = make_success_response().set_geocoded_features([new_york, las_vegas, los_angeles]).build()

df = Regions(
LevelKind.city,
[
make_region('Los Angeles', 'Los Angeles', '1', []),
make_region('New York', 'New York', '2', []),
make_region('Las Vegas', 'Las Vegas', '3', []),
make_region('Los Angeles', 'Los Angeles', '1', []),
]
level_kind=LevelKind.city,
queries=features_to_queries([los_angeles, new_york, las_vegas, los_angeles]),
answers=features_to_answers([los_angeles, new_york, las_vegas, los_angeles])
).centroids()

assert ['Los Angeles', 'New York', 'Las Vegas', 'Los Angeles'] == df[DF_FOUND_NAME].tolist()
Expand Down
6 changes: 5 additions & 1 deletion python-package/test/geo_data/test_georect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from pandas import DataFrame

from lets_plot.geo_data.gis.request import RegionQuery
from lets_plot.geo_data.gis.response import Answer, GeoRect, FeatureBuilder
from lets_plot.geo_data import DF_FOUND_NAME, DF_ID, DF_REQUEST
from lets_plot.geo_data.to_geo_data_frame import LimitsGeoDataFrame
Expand Down Expand Up @@ -46,7 +47,7 @@ def make_rect(lon_min: float, lon_max: float) -> GeoRect:

def data_frame(r: GeoRect):
return LimitsGeoDataFrame().to_data_frame(
[
answers=[
Answer(NAME, [
FeatureBuilder() \
.set_id(ID) \
Expand All @@ -56,6 +57,9 @@ def data_frame(r: GeoRect):
.build_geocoded()
]
)
],
queries=[
RegionQuery(request=NAME)
]
)

Expand Down
Loading