Example #1
0
    def test_read_brooklyn_poverty(self):
        """examples.read_brooklyn_poverty"""
        from cartoframes.examples import read_brooklyn_poverty
        # method test
        bp = self.examples.read_brooklyn_poverty()
        self.assertIsInstance(bp, pd.DataFrame)
        self.assertGreaterEqual(bp.shape[0], 0)

        # function test
        bp = read_brooklyn_poverty()
        self.assertIsInstance(bp, pd.DataFrame)
        self.assertGreaterEqual(bp.shape[0], 0)
Example #2
0
    def test_dataset_write_polygons_dataset(self):
        self.assertNotExistsTable(self.test_write_table)

        from cartoframes.examples import read_brooklyn_poverty
        df = read_brooklyn_poverty()
        dataset = Dataset.from_dataframe(df).upload(
            table_name=self.test_write_table, context=self.cc)
        self.test_write_table = dataset.table_name

        result = self.cc.sql_client.send(
            'SELECT * FROM {} WHERE the_geom IS NOT NULL'.format(
                self.test_write_table))
        self.assertEqual(result['total_rows'], 2049)
Example #3
0
    def test_dataset_write_with_different_geometry_column(self):
        self.assertNotExistsTable(self.test_write_table)

        from cartoframes.examples import read_brooklyn_poverty
        df = read_brooklyn_poverty()
        df.rename(columns={'the_geom': 'geometry'}, inplace=True)
        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'], 2049)
Example #4
0
    def test_dataset_write_if_exists_fail_by_default(self):
        self.assertNotExistsTable(self.test_write_table)

        from cartoframes.examples import read_brooklyn_poverty
        df = read_brooklyn_poverty()
        dataset = Dataset.from_dataframe(df).upload(
            table_name=self.test_write_table, context=self.cc)
        self.test_write_table = dataset.table_name

        err_msg = (
            'Table with name {t} and schema {s} already exists in CARTO. Please choose a different `table_name`'
            'or use if_exists="replace" to overwrite it').format(
                t=self.test_write_table, s='public')
        with self.assertRaises(CartoException, msg=err_msg):
            dataset = Dataset.from_dataframe(df).upload(
                table_name=self.test_write_table, context=self.cc)

        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'], 2049)