Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Deprecate charts.list_charts #3320

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions lib/catalog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ Notice that the last part of the URL is the chart's slug, its identifier, in thi
df = charts.get_data('life-expectancy')
```

To see what charts are available, you can list them all.

```python
>>> slugs = charts.list_charts()
>>> slugs[:5]
['above-ground-biomass-in-forest-per-hectare',
'above-or-below-extreme-poverty-line-world-bank',
'abs-change-energy-consumption',
'absolute-change-co2',
'absolute-gains-in-mean-female-height']
```

### Data science API

Expand Down
11 changes: 1 addition & 10 deletions lib/catalog/owid/catalog/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

from dataclasses import dataclass
from typing import List, Optional
from typing import Optional

import pandas as pd

Expand All @@ -15,7 +15,6 @@
LicenseError, # noqa
_fetch_bundle,
_GrapherBundle,
_list_charts,
)


Expand Down Expand Up @@ -53,14 +52,6 @@ def __eq__(self, value: object) -> bool:
return isinstance(value, Chart) and value.slug == self.slug


def list_charts() -> List[str]:
"""
List all available charts published on Our World in Data, representing each via
a short slug that you can use with `get_data()`.
"""
return sorted(_list_charts())


def get_data(slug_or_url: str) -> pd.DataFrame:
"""
Fetch the data for a chart by its slug or by the URL of the chart.
Expand Down
8 changes: 0 additions & 8 deletions lib/catalog/owid/catalog/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import datetime as dt
import json
import re
from dataclasses import dataclass
from typing import Dict, List, Literal

Expand Down Expand Up @@ -162,10 +161,3 @@ def _fetch_bundle(slug: str) -> _GrapherBundle:
if d.metadata.get("origins"):
origins.append(d.metadata.pop("origins"))
return _GrapherBundle(config, dimensions, origins)


def _list_charts() -> List[str]:
content = requests.get("https://ourworldindata.org/charts").content.decode("utf-8")
links = re.findall('"(/grapher/[^"]+)"', content)
slugs = [link.strip('"').split("/")[-1] for link in links]
return sorted(set(slugs))
9 changes: 0 additions & 9 deletions lib/catalog/tests/test_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ def test_fetch_non_redistributable_chart():
chart.get_data()


def test_list_charts():
slugs = charts.list_charts()
assert len(slugs) > 0
assert "life-expectancy" in slugs

# all unique
assert len(slugs) == len(set(slugs))


def test_fetch_missing_chart():
with pytest.raises(charts.ChartNotFoundError):
charts.Chart("this-chart-does-not-exist").bundle
Expand Down
Loading