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

map_join is not working correctly when map=geocoder #380

Closed
alshan opened this issue May 28, 2021 · 2 comments
Closed

map_join is not working correctly when map=geocoder #380

alshan opened this issue May 28, 2021 · 2 comments
Assignees

Comments

@alshan
Copy link
Collaborator

alshan commented May 28, 2021

from lets_plot import *
from lets_plot.geo_data import *

# %%

offices = [
    ["Prague", "CZ", "Headquarters", 100],
    ["Petersburg", "Russia", "R&D Center", 1000],
    ["Moscow", "Russia", "R&D Center", 100],
    ["Novosibirsk", "Russia", "R&D Center", 50],
    ["München", "Germany", "R&D Center", 200],
    ["Amsterdam", "Netherlands", "R&D Center", 100],
    ["Boston", "US", "R&D Center", 10],
    ["Marlton", "US", "Sales", 10],
    ["Foster City", "US", "Sales", 10],
]

dat = dict(
    city=[o[0] for o in offices],
    country=[o[1] for o in offices],
    kind=[o[2] for o in offices],
    size=[o[3] for o in offices],
)

# %%

# Geocoding
city_geocoder = geocode_cities(dat['city']).countries(dat['country'])

# %%

# The map of JetBrains major offices worldwide.
p = (ggplot(dat) +
     # geom_livemap() +
     geom_point(
         # aes(color='kind', shape='kind', size='size'),
         aes(color='kind'),
         size=10,
         map_join = ['city', 'city'],
         map=city_geocoder))
         # map=city_geocoder.get_centroids()))

p.show()

image

When using map=city_geocoder.get_centroids() it works as expected.

@IKupriyanov-HORIS
Copy link
Collaborator

Interesting thing that map=geocoder is actually works as expected.

In your example lets-plot deduces the following:
map_join=[['city', 'city'], ['city', 'country']]
It's because of a single list in map_join that is interpreted as multi-key for data. And as there is no explicit keys for map lets-plot tries to deduce keys by searching known geo-name columns - 'city', 'county', 'state', 'country'.

Sadly there are exactly two matching columns in a map - 'city', 'country'. That's why everything works without errors, but result is incorrect.

Proper way to define map_join for this case is to use pair of lists:
map_join = [['city'], ['city']]

@IKupriyanov-HORIS
Copy link
Collaborator

IKupriyanov-HORIS commented Jun 29, 2021

This commit changes map_join parsing policy:

  • if map_join is a list of string then it have to have 1 or 2 items, each item is considered as a simple key for data and map.
  • if map_join is a list of lists of string then it have to have 1 or 2 nested lists, each nested list is considered as a multi-key for data and map.

Second map_join item can be omitted only if map parameter is a Geocoder or GeoDataFrame, returned by a Geocoder geometries fetching functions.

As result initial code in the issue is now fully working and doesn't require any modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants