def test_dataset_write_geopandas(self): self.assertNotExistsTable(self.test_write_table) from cartoframes.examples import read_taxi import shapely import geopandas as gpd df = read_taxi(limit=50) df.drop(['the_geom'], axis=1, inplace=True) gdf = gpd.GeoDataFrame( df.drop(['dropoff_longitude', 'dropoff_latitude'], axis=1), crs={'init': 'epsg:4326'}, geometry=[ shapely.geometry.Point(xy) for xy in zip(df.dropoff_longitude, df.dropoff_latitude) ]) # TODO: use from_geodataframe dataset = Dataset.from_dataframe(gdf).upload( table_name=self.test_write_table, context=self.cc) self.test_write_table = dataset.table_name self.assertExistsTable(self.test_write_table) result = self.cc.sql_client.send( 'SELECT * FROM {} WHERE the_geom IS NOT NULL'.format( self.test_write_table)) self.assertEqual(result['total_rows'], 50)
def test_read_taxi(self): """examples.read_taxi""" from cartoframes.examples import read_taxi # method test taxi = self.examples.read_taxi() self.assertIsInstance(taxi, pd.DataFrame) self.assertGreater(taxi.shape[0], 0) # function test taxi = read_taxi() self.assertIsInstance(taxi, pd.DataFrame) self.assertGreater(taxi.shape[0], 0)
def test_dataset_write_null_geometry_column(self): self.assertNotExistsTable(self.test_write_table) from cartoframes.examples import read_taxi df = read_taxi(limit=100) dataset = Dataset.from_dataframe(df).upload( table_name=self.test_write_table, context=self.cc) self.test_write_table = dataset.table_name self.assertExistsTable(self.test_write_table) result = self.cc.sql_client.send( 'SELECT * FROM {} WHERE the_geom IS NULL'.format( self.test_write_table)) self.assertEqual(result['total_rows'], 100)
def test_dataset_write_wkt(self): self.assertNotExistsTable(self.test_write_table) from cartoframes.examples import read_taxi df = read_taxi(limit=50) df['the_geom'] = df.apply(lambda x: 'POINT ({x} {y})'.format( x=x['dropoff_longitude'], y=x['dropoff_latitude']), axis=1) dataset = Dataset.from_dataframe(df).upload( table_name=self.test_write_table, context=self.cc) self.test_write_table = dataset.table_name self.assertExistsTable(self.test_write_table) result = self.cc.sql_client.send( 'SELECT * FROM {} WHERE the_geom IS NOT NULL'.format( self.test_write_table)) self.assertEqual(result['total_rows'], 50)
def test_dataset_write_lnglat_dataset(self): self.assertNotExistsTable(self.test_write_table) from cartoframes.examples import read_taxi df = read_taxi(limit=100) lnglat = ('dropoff_longitude', 'dropoff_latitude') dataset = Dataset.from_dataframe(df).upload( with_lnglat=lnglat, table_name=self.test_write_table, context=self.cc) self.test_write_table = dataset.table_name self.assertExistsTable(self.test_write_table) result = self.cc.sql_client.send( 'SELECT * FROM {} WHERE the_geom IS NOT NULL'.format( self.test_write_table)) self.assertEqual(result['total_rows'], 100)