def test_case(): usa = geodata.geocode_countries(names=['usa']) states_48 = geodata.geocode_states(['us-48']) states_list = ['NY', 'TX', 'louisiana'] states = geodata.geocode_states(names=states_list).scope(usa) cities_list = ['New york', 'boston', 'la'] t_cities = geodata.geocode_cities(names=cities_list).scope(usa)
def test_duplication_with_us48(): df = geodata.geocode_states(names=['tx', 'us-48', 'tx']).get_geocodes() assert 51 == len(df) assert_row(df, names='tx', found_name='Texas', index=0) assert_row(df, names='Vermont', found_name='Vermont', index=1) assert_row(df, names='tx', found_name='Texas', index=50)
def test_regions_parents_in_regions_object_and_geo_data_frame(): # parent request from regions object should be propagated to resulting GeoDataFrame massachusetts = geodata.geocode_states('massachusetts') boston = geodata.geocode_cities('boston').states(massachusetts) assert_row(boston.get_geocodes(), names='boston', state='massachusetts', county=NO_COLUMN, country=NO_COLUMN) assert_row(boston.get_centroids(), names='boston', state='massachusetts', county=NO_COLUMN, country=NO_COLUMN)
def test_duplications_in_filter_should_preserve_order(): states = geodata.geocode_states(['Texas', 'TX', 'Arizona', 'Texas']).get_geocodes() assert_row( states, names=['Texas', 'TX', 'Arizona', 'Texas'], found_name=['Texas', 'Texas', 'Arizona', 'Texas'] )
def test_empty_request_name_columns(geometry_getter): request = 'Vermont' found_name = 'Vermont' states = geodata.geocode_states('us-48') assert_row(states.get_geocodes(), names=request, found_name=found_name) assert_row(geometry_getter(states), names=request, found_name=found_name)
def test_parents_lists(): states = geodata.geocode_states(['texas', 'nevada']).countries(['usa', 'usa']) assert_row(states.get_geocodes(), names=['texas', 'nevada'], found_name=['Texas', 'Nevada'], country=['usa', 'usa'] )
def test_with_drop_not_found(): states = geodata.geocode_states(['texas', 'trololo', 'nevada']) \ .countries(['usa', 'usa', 'usa']) \ .ignore_not_found() assert_row(states.get_geocodes(), names=['texas', 'nevada'], found_name=['Texas', 'Nevada'], country=['usa', 'usa']) assert_row(states.get_centroids(), names=['texas', 'nevada'], found_name=['Texas', 'Nevada'], country=['usa', 'usa']) assert_row(states.get_boundaries(), names=['texas', 'nevada'], found_name=['Texas', 'Nevada'], country=['usa', 'usa']) assert_row(states.get_limits(), names=['texas', 'nevada'], found_name=['Texas', 'Nevada'], country=['usa', 'usa'])
def test_where_request_level_detection(): """ where('new york', region=geodata.geocode_states('new york')) gives county as first detected level where('boston', region=geodata.geocode_countries('usa')) gives city as first detected level But 'new york' also matches a city name so common level should be a city """ r = geodata.geocode(names=['new york', 'boston']) \ .where('new york', scope=geodata.geocode_states('new york')) \ .where('boston', scope=geodata.geocode_countries('usa')) \ .get_geocodes() assert [NYC_ID, BOSTON_ID] == r.id.tolist()
def test_counties(): counties = [] states = [] for state in geodata.geocode_states("us-48").get_geocodes()['found name']: for county in geodata.geocode_counties().states(state).scope('usa').get_geocodes()['found name']: states.append(state) counties.append(county) geocoded_counties = geodata.geocode_counties(counties).states(states).scope('usa').get_boundaries('country') assert_row(geocoded_counties, names=counties)
def test_list_of_regions_parents_in_regions_object_and_geo_data_frame(): # parent request from regions object should be propagated to resulting GeoDataFrame states = geodata.geocode_states(['massachusetts', 'texas']) cities = geodata.geocode_cities(['boston', 'austin']).states(states) assert_row(cities.get_geocodes(), names=['boston', 'austin'], state=['massachusetts', 'texas'], county=NO_COLUMN, country=NO_COLUMN ) assert_row(cities.get_geocodes(), names=['boston', 'austin'], state=['massachusetts', 'texas'], county=NO_COLUMN, country=NO_COLUMN )
def test_for_us48_request_should_contain_feature_name(): states = geocode_states('us-48') assert_row(states.get_geocodes(), names=['foo', 'bar', 'baz'], found_name=['foo', 'bar', 'baz'])
def test_error_us48_in_request_not_available(): assert_error( "us-48 can't be used in requests with parents.", lambda: geodata.geocode_states('us-48').countries('usa').get_geocodes( ))
def test_us48_in_names_with_level(): us48 = geodata.geocode_states('us-48').get_geocodes() assert 49 == len(us48) assert_request_and_found_name_are_equal(us48)
def test_us48_in_scope(): df = geodata.geocode_states().scope('us-48').get_geocodes() assert 49 == len(df) assert_request_and_found_name_are_equal(df)
def test_should_copy_found_name_to_request_for_us48(): df = geodata.geocode_states('us-48').get_geocodes() assert len(df) == 49 assert_request_and_found_name_are_equal(df)
def test_geocoderegion_as_region(): usa = geodata.geocode_countries(names=['usa']) states_list = ['NY', 'TX', 'NV'] geodata.geocode_states(names=states_list).scope(usa).get_geocodes()