Repository: CartoDB/cartoframes
Pull request #1073 (2019-10-09 08:59:14)

Update country and lang column names in views
Columns "country_iso_code3" and "language_iso_code3" have been renamed in the views to "country_id" and "lang". This PR applies those renames so the catalog can work again.


Patch:
diff --git a/cartoframes/data/observatory/dataset.py b/cartoframes/data/observatory/dataset.py
index 222c73c0..b60d2a49 100644
--- a/cartoframes/data/observatory/dataset.py
+++ b/cartoframes/data/observatory/dataset.py
@@ -39,11 +39,11 @@ class Dataset(CatalogEntity):
 
     @property
     def country(self):
-        return self.data['country_iso_code3']
+        return self.data['country_id']
 
     @property
     def language(self):
-        return self.data['language_iso_code3']
+        return self.data['lang']
 
     @property
     def geography(self):
diff --git a/cartoframes/data/observatory/geography.py b/cartoframes/data/observatory/geography.py
index 8162e3ad..bd9656da 100644
--- a/cartoframes/data/observatory/geography.py
+++ b/cartoframes/data/observatory/geography.py
@@ -23,11 +23,11 @@ class Geography(CatalogEntity):
 
     @property
     def country(self):
-        return self.data['country_iso_code3']
+        return self.data['country_id']
 
     @property
     def language(self):
-        return self.data['language_iso_code3']
+        return self.data['lang']
 
     @property
     def provider(self):
diff --git a/cartoframes/data/observatory/repository/country_repo.py b/cartoframes/data/observatory/repository/country_repo.py
index 452fabe0..50963031 100644
--- a/cartoframes/data/observatory/repository/country_repo.py
+++ b/cartoframes/data/observatory/repository/country_repo.py
@@ -3,7 +3,7 @@ from __future__ import absolute_import
 from .entity_repo import EntityRepository
 
 
-_COUNTRY_ID_FIELD = 'country_iso_code3'
+_COUNTRY_ID_FIELD = 'country_id'
 
 
 def get_country_repo():
diff --git a/cartoframes/data/observatory/repository/dataset_repo.py b/cartoframes/data/observatory/repository/dataset_repo.py
index 40105d6c..3cbe7083 100644
--- a/cartoframes/data/observatory/repository/dataset_repo.py
+++ b/cartoframes/data/observatory/repository/dataset_repo.py
@@ -15,7 +15,7 @@ class DatasetRepository(EntityRepository):
     id_field = _DATASET_ID_FIELD
 
     def get_by_country(self, iso_code3):
-        return self._get_filtered_entities('country_iso_code3', iso_code3)
+        return self._get_filtered_entities('country_id', iso_code3)
 
     def get_by_category(self, category_id):
         return self._get_filtered_entities('category_id', category_id)
@@ -38,8 +38,8 @@ class DatasetRepository(EntityRepository):
             'provider_id': cls._normalize_field(row, 'provider_id'),
             'category_id': cls._normalize_field(row, 'category_id'),
             'data_source_id': cls._normalize_field(row, 'data_source_id'),
-            'country_iso_code3': cls._normalize_field(row, 'country_iso_code3'),
-            'language_iso_code3': cls._normalize_field(row, 'language_iso_code3'),
+            'country_id': cls._normalize_field(row, 'country_id'),
+            'lang': cls._normalize_field(row, 'lang'),
             'geography_id': cls._normalize_field(row, 'geography_id'),
             'temporal_aggregation': cls._normalize_field(row, 'temporal_aggregation'),
             'time_coverage': cls._normalize_field(row, 'time_coverage'),
diff --git a/cartoframes/data/observatory/repository/geography_repo.py b/cartoframes/data/observatory/repository/geography_repo.py
index 3bfeb404..290829ee 100644
--- a/cartoframes/data/observatory/repository/geography_repo.py
+++ b/cartoframes/data/observatory/repository/geography_repo.py
@@ -15,7 +15,7 @@ class GeographyRepository(EntityRepository):
     id_field = _GEOGRAPHY_ID_FIELD
 
     def get_by_country(self, iso_code3):
-        return self._get_filtered_entities('country_iso_code3', iso_code3)
+        return self._get_filtered_entities('country_id', iso_code3)
 
     @classmethod
     def _map_row(cls, row):
@@ -24,8 +24,8 @@ class GeographyRepository(EntityRepository):
             'name': cls._normalize_field(row, 'name'),
             'description': cls._normalize_field(row, 'description'),
             'provider_id': cls._normalize_field(row, 'provider_id'),
-            'country_iso_code3': cls._normalize_field(row, 'country_iso_code3'),
-            'language_iso_code3': cls._normalize_field(row, 'language_iso_code3'),
+            'country_id': cls._normalize_field(row, 'country_id'),
+            'lang': cls._normalize_field(row, 'lang'),
             'geom_coverage': cls._normalize_field(row, 'geom_coverage'),
             'update_frequency': cls._normalize_field(row, 'update_frequency'),
             'version': cls._normalize_field(row, 'version'),
diff --git a/cartoframes/data/observatory/repository/repo_client.py b/cartoframes/data/observatory/repository/repo_client.py
index 8eee6f81..77f45ee9 100644
--- a/cartoframes/data/observatory/repository/repo_client.py
+++ b/cartoframes/data/observatory/repository/repo_client.py
@@ -12,7 +12,7 @@ class RepoClient(object):
         self.client = SQLClient(Credentials('do-metadata', 'default_public'))
 
     def get_countries(self, field=None, value=None):
-        query = 'select distinct country_iso_code3 as id from datasets_public'
+        query = 'select distinct country_id as id from datasets_public'
         return self._run_query(query, field, value)
 
     def get_categories(self, field=None, value=None):


Test patch:
diff --git a/test/data/observatory/examples.py b/test/data/observatory/examples.py
index 8a0bd192..c2b3054a 100644
--- a/test/data/observatory/examples.py
+++ b/test/data/observatory/examples.py
@@ -30,8 +30,8 @@ db_geography1 = {
     'name': 'ESP - Census',
     'description': 'Geography data for Spanish census',
     'provider_id': 'bbva',
-    'country_iso_code3': 'esp',
-    'language_iso_code3': 'esp',
+    'country_id': 'esp',
+    'lang': 'esp',
     'geom_coverage': '',
     'update_frequency': 'monthly',
     'version': '20190203',
@@ -43,8 +43,8 @@ db_geography2 = {
     'name': 'ESP - Municipalities',
     'description': 'Geography data for Spanish municipalities',
     'provider_id': 'bbva',
-    'country_iso_code3': 'esp',
-    'language_iso_code3': 'esp',
+    'country_id': 'esp',
+    'lang': 'esp',
     'geom_coverage': '',
     'update_frequency': 'monthly',
     'version': '20190203',
@@ -62,8 +62,8 @@ db_dataset1 = {
     'provider_id': 'bbva',
     'category_id': 'demographics',
     'data_source_id': 'basicstats',
-    'country_iso_code3': 'esp',
-    'language_iso_code3': 'esp',
+    'country_id': 'esp',
+    'lang': 'esp',
     'geography_id': 'carto-do-public-data.tiger.geography_esp_census_2019',
     'temporal_aggregation': '5yrs',
     'time_coverage': ['2006-01-01', '2010-01-01'],
@@ -79,8 +79,8 @@ db_dataset2 = {
     'provider_id': 'bbva',
     'category_id': 'demographics',
     'data_source_id': 'basicstats',
-    'country_iso_code3': 'esp',
-    'language_iso_code3': 'esp',
+    'country_id': 'esp',
+    'lang': 'esp',
     'geography_id': 'carto-do-public-data.tiger.geography_esp_municipalities_2019',
     'temporal_aggregation': '5yrs',
     'time_coverage': ['2006-01-01', '2010-01-01'],
diff --git a/test/data/observatory/repository/test_country_repo.py b/test/data/observatory/repository/test_country_repo.py
index 21c15542..243a7e4a 100644
--- a/test/data/observatory/repository/test_country_repo.py
+++ b/test/data/observatory/repository/test_country_repo.py
@@ -52,7 +52,7 @@ class TestCountryRepo(unittest.TestCase):
         country = repo.get_by_id(requested_iso_code)
 
         # Then
-        mocked_repo.assert_called_once_with('country_iso_code3', requested_iso_code)
+        mocked_repo.assert_called_once_with('country_id', requested_iso_code)
         assert isinstance(country, Country)
         assert country == test_country1
 
diff --git a/test/data/observatory/repository/test_dataset_repo.py b/test/data/observatory/repository/test_dataset_repo.py
index 6c7b73b6..fc7f228e 100644
--- a/test/data/observatory/repository/test_dataset_repo.py
+++ b/test/data/observatory/repository/test_dataset_repo.py
@@ -79,7 +79,7 @@ class TestDatasetRepo(unittest.TestCase):
         datasets = repo.get_by_country(country_code)
 
         # Then
-        mocked_repo.assert_called_once_with('country_iso_code3', country_code)
+        mocked_repo.assert_called_once_with('country_id', country_code)
         assert isinstance(datasets, CatalogList)
         assert datasets == test_datasets
 
@@ -141,8 +141,8 @@ class TestDatasetRepo(unittest.TestCase):
             'provider_id': None,
             'category_id': None,
             'data_source_id': None,
-            'country_iso_code3': None,
-            'language_iso_code3': None,
+            'country_id': None,
+            'lang': None,
             'geography_id': None,
             'temporal_aggregation': None,
             'time_coverage': None,
diff --git a/test/data/observatory/repository/test_geography_repo.py b/test/data/observatory/repository/test_geography_repo.py
index 3f2fa8d2..bcec9397 100644
--- a/test/data/observatory/repository/test_geography_repo.py
+++ b/test/data/observatory/repository/test_geography_repo.py
@@ -79,7 +79,7 @@ class TestGeographyRepo(unittest.TestCase):
         geographies = repo.get_by_country(country_code)
 
         # Then
-        mocked_repo.assert_called_once_with('country_iso_code3', country_code)
+        mocked_repo.assert_called_once_with('country_id', country_code)
         assert isinstance(geographies, CatalogList)
         assert geographies == test_geographies
 
@@ -94,8 +94,8 @@ class TestGeographyRepo(unittest.TestCase):
             'name': None,
             'description': None,
             'provider_id': None,
-            'country_iso_code3': None,
-            'language_iso_code3': None,
+            'country_id': None,
+            'lang': None,
             'geom_coverage': None,
             'update_frequency': None,
             'version': None,
diff --git a/test/data/observatory/test_dataset.py b/test/data/observatory/test_dataset.py
index d85c6e0b..d8c29697 100644
--- a/test/data/observatory/test_dataset.py
+++ b/test/data/observatory/test_dataset.py
@@ -89,8 +89,8 @@ class TestDataset(unittest.TestCase):
         assert provider == db_dataset1['provider_id']
         assert category == db_dataset1['category_id']
         assert data_source == db_dataset1['data_source_id']
-        assert country == db_dataset1['country_iso_code3']
-        assert language == db_dataset1['language_iso_code3']
+        assert country == db_dataset1['country_id']
+        assert language == db_dataset1['lang']
         assert geography == db_dataset1['geography_id']
         assert temporal_aggregation == db_dataset1['temporal_aggregation']
         assert time_coverage == db_dataset1['time_coverage']
diff --git a/test/data/observatory/test_geography.py b/test/data/observatory/test_geography.py
index 2e6905c7..7c43514c 100644
--- a/test/data/observatory/test_geography.py
+++ b/test/data/observatory/test_geography.py
@@ -67,8 +67,8 @@ class TestGeography(unittest.TestCase):
         assert geography_id == db_geography1['id']
         assert name == db_geography1['name']
         assert description == db_geography1['description']
-        assert country == db_geography1['country_iso_code3']
-        assert language == db_geography1['language_iso_code3']
+        assert country == db_geography1['country_id']
+        assert language == db_geography1['lang']
         assert provider == db_geography1['provider_id']
         assert geom_coverage == db_geography1['geom_coverage']
         assert update_frequency == db_geography1['update_frequency']