How to use the cartoframes.data.observatory.Variable function in cartoframes

To help you get started, we’ve selected a few cartoframes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_points_enrichment.py View on Github external
_is_available_in_bq_mock):
        _is_available_in_bq_mock.return_value = True

        enrichment = Enrichment(credentials=self.credentials)

        temp_table_name = 'test_table'
        project = 'project'
        dataset = 'dataset'
        table = 'table'
        variable_name = 'variable1'
        column = 'column1'
        geo_table = 'geo_table'
        view = 'view_{}_{}'.format(dataset, table)
        geo_view = 'view_{}_{}'.format(dataset, geo_table)

        variable = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table, variable_name),
            'column_name': column,
            'dataset_id': 'fake_name'
        })
        variables = [variable]

        variable_filter = VariableFilter(variable, "= 'a string'")
        filters = [variable_filter]

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset, geo_table))
        dataset_get_mock.return_value = catalog
        geography_get_mock.return_value = GeographyMock()

        actual_queries = enrichment._get_points_enrichment_sql(
            temp_table_name, variables, filters
        )
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_polygon_enrichment.py View on Github external
enrichment = Enrichment(credentials=self.credentials)

        temp_table_name = 'test_table'
        project = 'project'
        dataset = 'dataset'
        table = 'table'
        variable1_name = 'variable1'
        variable2_name = 'variable2'
        column1 = 'column1'
        column2 = 'column2'
        geo_table = 'geo_table'
        view = 'view_{}_{}'.format(dataset, table)
        geo_view = 'view_{}_{}'.format(dataset, geo_table)
        agg = 'AVG'

        variable1 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table, variable1_name),
            'column_name': column1,
            'agg_method': agg,
            'dataset_id': 'fake_name'
        })
        variable2 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table, variable2_name),
            'column_name': column2,
            'agg_method': None,
            'dataset_id': 'fake_name'
        })
        variables = [variable1, variable2]
        aggregation = AGGREGATION_DEFAULT
        variables = prepare_variables(variables, self.credentials, aggregation)

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset, geo_table))
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_polygon_enrichment.py View on Github external
variable2_name = 'variable2'
        column1 = 'column1'
        column2 = 'column2'
        geo_table = 'geo_table'
        view1 = 'view_{}_{}'.format(dataset1, table1)
        view2 = 'view_{}_{}'.format(dataset2, table2)
        geo_view = 'view_{}_{}'.format(dataset1, geo_table)
        agg = 'AVG'

        variable1 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset1, table1, variable1_name),
            'column_name': column1,
            'agg_method': agg,
            'dataset_id': 'fake_name'
        })
        variable2 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset2, table2, variable2_name),
            'column_name': column2,
            'agg_method': agg,
            'dataset_id': 'fake_name'
        })
        variables = [variable1, variable2]

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset1, geo_table))
        dataset_get_mock.return_value = catalog
        geography_get_mock.return_value = GeographyMock()

        actual_queries = enrichment._get_polygon_enrichment_sql(
            temp_table_name, variables, [], AGGREGATION_DEFAULT
        )

        expected_queries = [
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_polygon_enrichment.py View on Github external
_is_available_in_bq_mock):
        _is_available_in_bq_mock.return_value = True

        enrichment = Enrichment(credentials=self.credentials)

        temp_table_name = 'test_table'
        project = 'project'
        dataset = 'dataset1'
        table = 'table1'
        variable_name = 'variable1'
        column = 'column1'
        geo_table = 'geo_table'
        view = 'view_{}_{}'.format(dataset, table)
        geo_view = 'view_{}_{}'.format(dataset, geo_table)

        variable = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table, variable_name),
            'column_name': column,
            'agg_method': 'should_not_be_used',
            'dataset_id': 'fake_name'
        })
        variables = [variable]

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset, geo_table))
        dataset_get_mock.return_value = catalog
        geography_get_mock.return_value = GeographyMock()

        actual_queries = enrichment._get_polygon_enrichment_sql(
            temp_table_name, variables, [], AGGREGATION_NONE
        )

        expected_queries = [
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_enrichment_service.py View on Github external
def test_prepare_variables_without_agg_method_and_custom_agg(self, get_mock, _validate_bq_operations_mock):
        _validate_bq_operations_mock.return_value = True

        variable_id = 'project.dataset.table.variable'
        variable = Variable({
            'id': variable_id,
            'column_name': 'column',
            'dataset_id': 'fake_name',
            'agg_method': None
        })

        get_mock.return_value = variable

        credentials = Credentials('fake_user', '1234')

        one_variable_cases = [
            variable_id,
            variable
        ]

        for case in one_variable_cases:
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_polygon_enrichment.py View on Github external
variable2_name = 'variable2'
        column1 = 'column1'
        column2 = 'column2'
        geo_table = 'geo_table'
        view1 = 'view_{}_{}'.format(dataset, table1)
        view2 = 'view_{}_{}'.format(dataset, table2)
        geo_view = 'view_{}_{}'.format(dataset, geo_table)
        agg = 'AVG'

        variable1 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table1, variable1_name),
            'column_name': column1,
            'agg_method': agg,
            'dataset_id': 'fake_name'
        })
        variable2 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table2, variable2_name),
            'column_name': column2,
            'agg_method': agg,
            'dataset_id': 'fake_name'
        })
        variables = [variable1, variable2]

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset, geo_table))
        dataset_get_mock.return_value = catalog
        geography_get_mock.return_value = GeographyMock()

        actual_queries = enrichment._get_polygon_enrichment_sql(
            temp_table_name, variables, [], AGGREGATION_DEFAULT
        )

        expected_queries = [
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_points_enrichment.py View on Github external
temp_table_name = 'test_table'
        project = 'project'
        dataset1 = 'dataset1'
        dataset2 = 'dataset2'
        table1 = 'table1'
        table2 = 'table2'
        variable1_name = 'variable1'
        variable2_name = 'variable2'
        column1 = 'column1'
        column2 = 'column2'
        geo_table = 'geo_table'
        view1 = 'view_{}_{}'.format(dataset1, table1)
        view2 = 'view_{}_{}'.format(dataset2, table2)
        geo_view = 'view_{}_{}'.format(dataset1, geo_table)

        variable1 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset1, table1, variable1_name),
            'column_name': column1,
            'dataset_id': 'fake_name'
        })
        variable2 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset2, table2, variable2_name),
            'column_name': column2,
            'dataset_id': 'fake_name'
        })
        variables = [variable1, variable2]

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset1, geo_table))
        dataset_get_mock.return_value = catalog
        geography_get_mock.return_value = GeographyMock()

        actual_queries = enrichment._get_points_enrichment_sql(
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_enrichment_service.py View on Github external
'id': 'id',
            'slug': 'slug',
            'name': 'name',
            'description': 'description',
            'available_in': ['bq'],
            'geography_id': 'geography',
            'is_public_data': True
        })

        # mock dataset
        entity_repo.return_value = dataset

        # mock subscriptions
        get_all_mock.return_value = []

        variable = Variable({
            'id': 'id',
            'column_name': 'column',
            'dataset_id': 'fake_name',
            'slug': 'slug'
        })

        get_mock.return_value = variable

        credentials = Credentials('fake_user', '1234')

        result = prepare_variables(variable, credentials)
        assert result == [variable]
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_enrichment_service.py View on Github external
'id': 'id',
            'slug': 'slug',
            'name': 'name',
            'description': 'description',
            'available_in': ['bq'],
            'geography_id': 'geography',
            'is_public_data': False
        })

        # mock dataset
        entity_repo.return_value = dataset

        # mock subscriptions
        get_all_mock.return_value = [dataset]

        variable = Variable({
            'id': 'id',
            'column_name': 'column',
            'dataset_id': 'fake_name',
            'slug': 'slug'
        })

        get_mock.return_value = variable

        credentials = Credentials('fake_user', '1234')

        result = prepare_variables(variable, credentials)
        assert result == [variable]
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_polygon_enrichment.py View on Github external
variable1_name = 'variable1'
        variable2_name = 'variable2'
        column1 = 'column1'
        column2 = 'column2'
        geo_table = 'geo_table'
        view = 'view_{}_{}'.format(dataset, table)
        geo_view = 'view_{}_{}'.format(dataset, geo_table)
        agg = 'AVG'

        variable1 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table, variable1_name),
            'column_name': column1,
            'agg_method': agg,
            'dataset_id': 'fake_name'
        })
        variable2 = Variable({
            'id': '{}.{}.{}.{}'.format(project, dataset, table, variable2_name),
            'column_name': column2,
            'agg_method': None,
            'dataset_id': 'fake_name'
        })
        variables = [variable1, variable2]
        aggregation = {variable2.id: agg}
        variables = prepare_variables(variables, self.credentials, aggregation)

        catalog = CatalogEntityWithGeographyMock('{}.{}.{}'.format(project, dataset, geo_table))
        dataset_get_mock.return_value = catalog
        geography_get_mock.return_value = GeographyMock()

        actual_queries = enrichment._get_polygon_enrichment_sql(
            temp_table_name, variables, [], aggregation
        )