def _prepare_location()

in python-package/lets_plot/geo_data/livemap_helper.py [0:0]


def _prepare_location(location: Union[str, Geocodes, List[float], DataFrame]) -> Optional[dict]:
    if location is None:
        return None

    value = location
    if isinstance(location, Geocodes):
        kind = RegionKind.region_ids
        value = location.unique_ids()

    elif isinstance(location, str):
        kind = RegionKind.region_name

    elif isinstance(location, list):
        if len(location) == 0 or len(location) % 2 != 0:
            raise ValueError(LOCATION_LIST_ERROR_MESSAGE)
        kind = RegionKind.coordinates

    elif isinstance(location, DataFrame):
        if not LOCATION_COORDINATE_COLUMNS.issubset(location.columns) and not LOCATION_RECTANGLE_COLUMNS.issubset(location.columns):
            raise ValueError(LOCATION_DATAFRAME_ERROR_MESSAGE)
        kind = RegionKind.data_frame

    else:
        raise ValueError('Wrong location type: ' + location.__str__())

    return {'type': kind.value, 'data': value}