def test_no_overlapping_geometry(self): # Note: these tests are for correctly returning GeoDataFrame # when result of the join is empty df_inner = sjoin(self.pointdf.iloc[17:], self.polydf, how='inner') df_left = sjoin(self.pointdf.iloc[17:], self.polydf, how='left') df_right = sjoin(self.pointdf.iloc[17:], self.polydf, how='right') # Recent Pandas development has introduced a new way of handling merges # this change has altered the output when no overlapping geometries if str(pd.__version__) > LooseVersion('0.18.1'): right_idxs = pd.Series(range(0, 5), name='index_right', dtype='int64') else: right_idxs = pd.Series(name='index_right', dtype='int64') expected_inner_df = pd.concat([ self.pointdf.iloc[:0], pd.Series(name='index_right', dtype='int64'), self.polydf.drop('geometry', axis=1).iloc[:0] ], axis=1) expected_inner = GeoDataFrame(expected_inner_df, crs={ 'init': 'epsg:4326', 'no_defs': True }) expected_right_df = pd.concat([ self.pointdf.drop('geometry', axis=1).iloc[:0], pd.concat( [pd.Series(name='index_left', dtype='int64'), right_idxs], axis=1), self.polydf ], axis=1) expected_right = GeoDataFrame( expected_right_df, crs={'init': 'epsg:4326', 'no_defs': True})\ .set_index('index_right') expected_left_df = pd.concat([ self.pointdf.iloc[17:], pd.Series(name='index_right', dtype='int64'), self.polydf.iloc[:0].drop('geometry', axis=1) ], axis=1) expected_left = GeoDataFrame(expected_left_df, crs={ 'init': 'epsg:4326', 'no_defs': True }) assert expected_inner.equals(df_inner) assert expected_right.equals(df_right) assert expected_left.equals(df_left)
def test_no_overlapping_geometry(self): # Note: these tests are for correctly returning GeoDataFrame # when result of the join is empty df_inner = sjoin(self.pointdf.iloc[17:], self.polydf, how="inner") df_left = sjoin(self.pointdf.iloc[17:], self.polydf, how="left") df_right = sjoin(self.pointdf.iloc[17:], self.polydf, how="right") expected_inner_df = pd.concat( [ self.pointdf.iloc[:0], pd.Series(name="index_right", dtype="int64"), self.polydf.drop("geometry", axis=1).iloc[:0], ], axis=1, ) expected_inner = GeoDataFrame( expected_inner_df, crs={"init": "epsg:4326", "no_defs": True} ) expected_right_df = pd.concat( [ self.pointdf.drop("geometry", axis=1).iloc[:0], pd.concat( [ pd.Series(name="index_left", dtype="int64"), pd.Series(name="index_right", dtype="int64"), ], axis=1, ), self.polydf, ], axis=1, ) expected_right = GeoDataFrame( expected_right_df, crs={"init": "epsg:4326", "no_defs": True} ).set_index("index_right") expected_left_df = pd.concat( [ self.pointdf.iloc[17:], pd.Series(name="index_right", dtype="int64"), self.polydf.iloc[:0].drop("geometry", axis=1), ], axis=1, ) expected_left = GeoDataFrame( expected_left_df, crs={"init": "epsg:4326", "no_defs": True} ) assert expected_inner.equals(df_inner) assert expected_right.equals(df_right) assert expected_left.equals(df_left)
def test_no_overlapping_geometry(self): # Note: these tests are for correctly returning GeoDataFrame # when result of the join is empty df_inner = sjoin(self.pointdf.iloc[17:], self.polydf, how='inner') df_left = sjoin(self.pointdf.iloc[17:], self.polydf, how='left') df_right = sjoin(self.pointdf.iloc[17:], self.polydf, how='right') # Recent Pandas development has introduced a new way of handling merges # this change has altered the output when no overlapping geometries if str(pd.__version__) > LooseVersion('0.18.1'): right_idxs = pd.Series(range(0, 5), name='index_right', dtype='int64') else: right_idxs = pd.Series(name='index_right', dtype='int64') expected_inner_df = pd.concat( [self.pointdf.iloc[:0], pd.Series(name='index_right', dtype='int64'), self.polydf.drop('geometry', axis=1).iloc[:0]], axis=1) expected_inner = GeoDataFrame( expected_inner_df, crs={'init': 'epsg:4326', 'no_defs': True}) expected_right_df = pd.concat( [self.pointdf.drop('geometry', axis=1).iloc[:0], pd.concat([pd.Series(name='index_left', dtype='int64'), right_idxs], axis=1), self.polydf], axis=1) expected_right = GeoDataFrame( expected_right_df, crs={'init': 'epsg:4326', 'no_defs': True})\ .set_index('index_right') expected_left_df = pd.concat( [self.pointdf.iloc[17:], pd.Series(name='index_right', dtype='int64'), self.polydf.iloc[:0].drop('geometry', axis=1)], axis=1) expected_left = GeoDataFrame( expected_left_df, crs={'init': 'epsg:4326', 'no_defs': True}) assert expected_inner.equals(df_inner) assert expected_right.equals(df_right) assert expected_left.equals(df_left)
def test_read_carto_decode_geom_false(mocker): # Given cm_mock = mocker.patch.object(ContextManager, 'copy_to') cm_mock.return_value = GeoDataFrame({ 'cartodb_id': [1, 2, 3], 'the_geom': [ '010100000000000000000000000000000000000000', '010100000000000000000024400000000000002e40', '010100000000000000000034400000000000003e40' ] }) expected = GeoDataFrame({ 'cartodb_id': [1, 2, 3], 'the_geom': [ '010100000000000000000000000000000000000000', '010100000000000000000024400000000000002e40', '010100000000000000000034400000000000003e40' ] }) # When gdf = read_carto('__source__', CREDENTIALS, decode_geom=False) # Then assert expected.equals(gdf)
def test_read_carto(mocker): # Given cm_mock = mocker.patch.object(ContextManager, 'copy_to') cm_mock.return_value = GeoDataFrame({ 'cartodb_id': [1, 2, 3], 'the_geom': [ '010100000000000000000000000000000000000000', '010100000000000000000024400000000000002e40', '010100000000000000000034400000000000003e40' ] }) expected = GeoDataFrame( { 'cartodb_id': [1, 2, 3], 'the_geom': [Point([0, 0]), Point([10, 15]), Point([20, 30])] }, geometry='the_geom') # When gdf = read_carto('__source__', CREDENTIALS) # Then cm_mock.assert_called_once_with('__source__', None, None, 3) assert expected.equals(gdf) assert gdf.crs == 'epsg:4326'
def test_read_carto_index_col_not_exists(mocker): # Given cm_mock = mocker.patch.object(ContextManager, 'copy_to') cm_mock.return_value = GeoDataFrame({ 'cartodb_id': [1, 2, 3], 'the_geom': [ '010100000000000000000000000000000000000000', '010100000000000000000024400000000000002e40', '010100000000000000000034400000000000003e40' ] }) expected = GeoDataFrame( { 'cartodb_id': [1, 2, 3], 'the_geom': [Point([0, 0]), Point([10, 15]), Point([20, 30])] }, geometry='the_geom', index=Index([0, 1, 2], name='rename_index')) # When gdf = read_carto('__source__', CREDENTIALS, index_col='rename_index') # Then assert expected.equals(gdf)
def test_no_overlapping_geometry(self): # Note: these tests are for correctly returning GeoDataFrame # when result of the join is empty df_inner = sjoin(self.pointdf.iloc[17:], self.polydf, how='inner') df_left = sjoin(self.pointdf.iloc[17:], self.polydf, how='left') df_right = sjoin(self.pointdf.iloc[17:], self.polydf, how='right') expected_inner_df = pd.concat( [self.pointdf.iloc[:0], pd.Series(name='index_right', dtype='int64'), self.polydf.drop('geometry', axis=1).iloc[:0]], axis=1) expected_inner = GeoDataFrame( expected_inner_df, crs={'init': 'epsg:4326', 'no_defs': True}) expected_right_df = pd.concat( [self.pointdf.drop('geometry', axis=1).iloc[:0], pd.concat([pd.Series(name='index_left', dtype='int64'), pd.Series(name='index_right', dtype='int64')], axis=1), self.polydf], axis=1) expected_right = GeoDataFrame( expected_right_df, crs={'init': 'epsg:4326', 'no_defs': True})\ .set_index('index_right') expected_left_df = pd.concat( [self.pointdf.iloc[17:], pd.Series(name='index_right', dtype='int64'), self.polydf.iloc[:0].drop('geometry', axis=1)], axis=1) expected_left = GeoDataFrame( expected_left_df, crs={'init': 'epsg:4326', 'no_defs': True}) assert expected_inner.equals(df_inner) assert expected_right.equals(df_right) assert expected_left.equals(df_left)
def test_read_carto_basegeometry_as_null_geom_value(mocker): # Given cm_mock = mocker.patch.object(ContextManager, 'copy_to') cm_mock.return_value = GeoDataFrame({ 'cartodb_id': [1], 'the_geom': [None] }) # When gdf = read_carto('__source__', CREDENTIALS, null_geom_value=BaseGeometry()) # Then expected = GeoDataFrame({ 'cartodb_id': [1], 'the_geom': [BaseGeometry()] }, geometry='the_geom') cm_mock.assert_called_once_with('__source__', None, None, 3) assert expected.equals(gdf) assert gdf.crs == 'epsg:4326'