Skip to content

Commit

Permalink
Merge pull request #1404 from CartoDB/1369-remove-get-catalog
Browse files Browse the repository at this point in the history
Remove get from CatalogList
  • Loading branch information
Jesus89 committed Dec 23, 2019
2 parents 7cd927d + ce61236 commit 815c7b4
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 182 deletions.
5 changes: 2 additions & 3 deletions cartoframes/data/observatory/catalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ class Catalog(object):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Dataset
catalog = Catalog()
dataset = catalog.country('usa').category('demographics').datasets.get('od_acs_13345497')
dataset = Dataset.get('od_acs_13345497')
dataset.variables()
See the Catalog guides and examples in our
Expand Down
23 changes: 10 additions & 13 deletions cartoframes/data/observatory/catalog/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ class Category(CatalogEntity):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Category
catalog = Catalog()
category = catalog.categories.get('demographics')
category = Category.get('demographics')
"""

_entity_repo = get_category_repo()
Expand All @@ -52,10 +51,9 @@ def datasets(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Category
catalog = Catalog()
category = catalog.categories.get('demographics')
category = Category.get('demographics')
datasets = category.datasets
Same example as above but using nested filters:
Expand All @@ -72,15 +70,15 @@ def datasets(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Catalog, Dataset
catalog = Catalog()
datasets = catalog.category('demographics').datasets
# convert the list of datasets into a pandas DataFrame
# for further filtering and exploration
dataframe = datasets.to_dataframe()
# get a dataset by ID or slug
dataset = datasets.get(A_VALID_ID_OR_SLUG)
dataset = Dataset.get(A_VALID_ID_OR_SLUG)
"""
return get_dataset_repo().get_all({CATEGORY_FILTER: self.id})

Expand All @@ -100,10 +98,9 @@ def geographies(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Category
catalog = Catalog()
category = catalog.categories.get('demographics')
category = Category.get('demographics')
geographies = category.geographies
Same example as above but using nested filters:
Expand All @@ -120,15 +117,15 @@ def geographies(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Catalog, Geography
catalog = Catalog()
geographies = catalog.category('demographics').geographies
# convert the list of datasets into a pandas DataFrame
# for further filtering and exploration
dataframe = geographies.to_dataframe()
# get a geography by ID or slug
dataset = geographies.get(A_VALID_ID_OR_SLUG)
dataset = Geography.get(A_VALID_ID_OR_SLUG)
"""
return get_geography_repo().get_all({CATEGORY_FILTER: self.id})

Expand Down
28 changes: 12 additions & 16 deletions cartoframes/data/observatory/catalog/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ class Country(CatalogEntity):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Country
catalog = Catalog()
# country ID is a lowercase ISO Alpha 3 Code
category = catalog.countries.get('usa')
country = Country.get('usa')
"""

_entity_repo = get_country_repo()
Expand All @@ -53,10 +52,9 @@ def datasets(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Country
catalog = Catalog()
country = catalog.countries.get('usa')
country = Country.get('usa')
datasets = country.datasets
Same example as above but using nested filters:
Expand All @@ -73,14 +71,14 @@ def datasets(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Catalog, Dataset
datasets = catalog.country('usa').datasets
# convert the list of datasets into a pandas DataFrame
# for further filtering and exploration
dataframe = datasets.to_dataframe()
# get a dataset by ID or slug
dataset = datasets.get(A_VALID_ID_OR_SLUG)
dataset = Dataset.get(A_VALID_ID_OR_SLUG)
"""
return get_dataset_repo().get_all({COUNTRY_FILTER: self.id})
Expand All @@ -101,10 +99,9 @@ def geographies(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Country
catalog = Catalog()
country = catalog.countries.get('usa')
country = Country.get('usa')
geographies = country.geographies
Same example as above but using nested filters:
Expand All @@ -121,14 +118,14 @@ def geographies(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Catalog, Geography
geographies = catalog.country('usa').geographies
# convert the list of geographies into a pandas DataFrame
# for further filtering and exploration
dataframe = geographies.to_dataframe()
# get a geography by ID or slug
geography = geographies.get(A_VALID_ID_OR_SLUG)
geography = Geography.get(A_VALID_ID_OR_SLUG)
"""
return get_geography_repo().get_all({COUNTRY_FILTER: self.id})
Expand All @@ -149,10 +146,9 @@ def categories(self):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Country
catalog = Catalog()
country = catalog.countries.get('usa')
country = Country.get('usa')
categories = country.categories
Same example as above but using nested filters:
Expand Down
15 changes: 0 additions & 15 deletions cartoframes/data/observatory/catalog/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ class CatalogList(list):
def __init__(self, data):
super(CatalogList, self).__init__(data)

def get(self, item_id):
"""Gets an entity by ID or slug
Examples:
.. code::
from cartoframes.data.observatory import Catalog
catalog = Catalog()
category = catalog.categories.get('demographics')
"""
return next(iter(filter(lambda item: item.id == item_id or item.slug == item_id, self)), None)

def to_dataframe(self):
"""Converts a list to a pandas DataFrame.
Expand Down
9 changes: 9 additions & 0 deletions cartoframes/data/observatory/catalog/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def datasets(self):
Examples:
.. code::
from cartoframes.data.observatory import Provider
provider = Provider.get('mrli')
datasets = provider.datasets
Same example as above but using nested filters:
.. code::
from cartoframes.data.observatory import Catalog
Expand Down
5 changes: 2 additions & 3 deletions cartoframes/data/observatory/catalog/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class Variable(CatalogEntity):
.. code::
from cartoframes.data.observatory import Catalog
from cartoframes.data.observatory import Dataset
catalog = new Catalog()
dataset = catalog.country('usa').category('demographics').datasets.get('mbi_retail_turn_705247a')
dataset = Dataset.get('mbi_retail_turn_705247a')
dataset.variables
"""

Expand Down
12 changes: 0 additions & 12 deletions tests/unit/data/observatory/catalog/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ def test_get_category_by_id(self, mocked_repo):
assert isinstance(category, Category)
assert category == test_category1

def test_get_category_by_id_from_categories_list(self):
# Given
categories = CatalogList([test_category1, test_category2])

# When
category = categories.get(test_category1.id)

# Then
assert isinstance(category, object)
assert isinstance(category, Category)
assert category == test_category1

@patch.object(DatasetRepository, 'get_all')
def test_get_datasets_by_category(self, mocked_repo):
# Given
Expand Down
12 changes: 0 additions & 12 deletions tests/unit/data/observatory/catalog/test_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ def test_get_country_by_id(self, mocked_repo):
assert isinstance(country, Country)
assert country == test_country1

def test_get_country_by_id_from_countries_list(self):
# Given
countries = CatalogList([test_country1, test_country2])

# When
country = countries.get(test_country1.id)

# Then
assert isinstance(country, object)
assert isinstance(country, Country)
assert country == test_country1

@patch.object(DatasetRepository, 'get_all')
def test_get_datasets_by_country(self, mocked_repo):
# Given
Expand Down
24 changes: 0 additions & 24 deletions tests/unit/data/observatory/catalog/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@ def test_get_dataset_by_id(self, mocked_repo):
assert isinstance(dataset, Dataset)
assert dataset == test_dataset1

def test_get_dataset_by_id_from_datasets_list(self):
# Given
datasets = CatalogList([test_dataset1, test_dataset2])

# When
dataset = datasets.get(test_dataset1.id)

# Then
assert isinstance(dataset, object)
assert isinstance(dataset, Dataset)
assert dataset == test_dataset1

def test_get_dataset_by_slug_from_datasets_list(self):
# Given
datasets = CatalogList([test_dataset1, test_dataset2])

# When
dataset = datasets.get(test_dataset1.slug)

# Then
assert isinstance(dataset, object)
assert isinstance(dataset, Dataset)
assert dataset == test_dataset1

@patch.object(VariableRepository, 'get_all')
def test_get_variables_by_dataset(self, mocked_repo):
# Given
Expand Down
24 changes: 0 additions & 24 deletions tests/unit/data/observatory/catalog/test_geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,6 @@ def test_get_geography_by_id(self, mocked_repo):
assert isinstance(geography, Geography)
assert geography == test_geography1

def test_get_geography_by_id_from_geographies_list(self):
# Given
geographies = CatalogList([test_geography1, test_geography2])

# When
geography = geographies.get(test_geography1.id)

# Then
assert isinstance(geography, object)
assert isinstance(geography, Geography)
assert geography == test_geography1

def test_get_geography_by_slug_from_geographies_list(self):
# Given
geographies = CatalogList([test_geography1, test_geography2])

# When
geography = geographies.get(test_geography1.slug)

# Then
assert isinstance(geography, object)
assert isinstance(geography, Geography)
assert geography == test_geography1

@patch.object(DatasetRepository, 'get_all')
def test_get_datasets_by_geography(self, mocked_repo):
# Given
Expand Down
12 changes: 0 additions & 12 deletions tests/unit/data/observatory/catalog/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ def test_get_provider_by_id(self, mocked_repo):
assert isinstance(provider, Provider)
assert provider == test_provider1

def test_get_provider_by_id_from_providers_list(self):
# Given
providers = CatalogList([test_provider1, test_provider2])

# When
provider = providers.get(test_provider1.id)

# Then
assert isinstance(provider, object)
assert isinstance(provider, Provider)
assert provider == test_provider1

@patch.object(DatasetRepository, 'get_all')
def test_get_datasets_by_provider(self, mocked_repo):
# Given
Expand Down
24 changes: 0 additions & 24 deletions tests/unit/data/observatory/catalog/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,6 @@ def test_get_variable_by_id(self, mocked_repo):
assert isinstance(variable, Variable)
assert variable == test_variable1

def test_get_variable_by_id_from_variables_list(self):
# Given
variables = CatalogList([test_variable1, test_variable2])

# When
variable = variables.get(test_variable1.id)

# Then
assert isinstance(variable, object)
assert isinstance(variable, Variable)
assert variable == test_variable1

def test_get_variable_by_slug_from_variables_list(self):
# Given
variables = CatalogList([test_variable1, test_variable2])

# When
variable = variables.get(test_variable1.slug)

# Then
assert isinstance(variable, object)
assert isinstance(variable, Variable)
assert variable == test_variable1

@patch.object(DatasetRepository, 'get_all')
def test_get_datasets_by_variable(self, mocked_repo):
# Given
Expand Down

0 comments on commit 815c7b4

Please sign in to comment.