Skip to content

Commit c79a8bb

Browse files
committed
DataItem -> Dataset
1 parent bd6714b commit c79a8bb

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

doc/source/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Database-level API
2727

2828
The database of dataset metadata is handled via custom dict-based classes.
2929

30-
.. class:: DataItem
30+
.. class:: Dataset
3131

3232
A dict with attribute-access and that can be called to update keys.
3333

doc/source/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ contributions to the codebase and documentation.
1111
If you want to add a new dataset, simply add its details to
1212
`geodatasets/json/database.json`.
1313

14-
You can add a single `DataItem` or a `Bunch` of `DataItem`s. Use the following
14+
You can add a single `Dataset` or a `Bunch` of `Dataset`s. Use the following
1515
schema to add a single dataset:
1616

1717
```json

doc/source/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ maxdepth: 2
77
caption: Documentation
88
hidden: true
99
---
10+
introduction
1011
api
1112
contributing
1213
GitHub <https://github.com/geopandas/geodatasets>

geodatasets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .api import get_path, get_url, fetch # noqa
22
from .data import data # noqa
3-
from .lib import Bunch, DataItem # noqa
3+
from .lib import Bunch, Dataset # noqa
44

55
from importlib.metadata import PackageNotFoundError, version
66

geodatasets/lib.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Bunch(dict):
1616
"""A dict with attribute-access
1717
18-
:class:`Bunch` is used to store :class:`DataItem` objects.
18+
:class:`Bunch` is used to store :class:`Dataset` objects.
1919
"""
2020

2121
def __getattr__(self, key):
@@ -31,8 +31,8 @@ def _repr_html_(self, inside=False):
3131

3232
children = ""
3333
for key in self.keys():
34-
if isinstance(self[key], DataItem):
35-
obj = "geodatasets.DataItem"
34+
if isinstance(self[key], Dataset):
35+
obj = "geodatasets.Dataset"
3636
else:
3737
obj = "geodatasets.Bunch"
3838
uid = str(uuid.uuid4())
@@ -69,19 +69,19 @@ def _repr_html_(self, inside=False):
6969
def flatten(self) -> dict:
7070
"""Return the nested :class:`Bunch` collapsed into the one level dictionary.
7171
72-
Dictionary keys are :class:`DataItem` names (e.g. ``geoda.airbnb``)
73-
and its values are :class:`DataItem` objects.
72+
Dictionary keys are :class:`Dataset` names (e.g. ``geoda.airbnb``)
73+
and its values are :class:`Dataset` objects.
7474
7575
Returns
7676
-------
7777
flattened : dict
78-
dictionary of :class:`DataItem` objects
78+
dictionary of :class:`Dataset` objects
7979
"""
8080

8181
flat = {}
8282

8383
def _get_items(item):
84-
if isinstance(item, DataItem):
84+
if isinstance(item, Dataset):
8585
flat[item.name] = item
8686
else:
8787
for prov in item.values():
@@ -91,10 +91,10 @@ def _get_items(item):
9191

9292
return flat
9393

94-
def query_name(self, name: str) -> DataItem:
95-
"""Return :class:`DataItem` based on the name query
94+
def query_name(self, name: str) -> Dataset:
95+
"""Return :class:`Dataset` based on the name query
9696
97-
Returns a matching :class:`DataItem` from the :class:`Bunch` if the ``name``
97+
Returns a matching :class:`Dataset` from the :class:`Bunch` if the ``name``
9898
contains the same letters in the same order as the item's name irrespective
9999
of the letter case, spaces, dashes and other characters.
100100
See examples for details.
@@ -106,7 +106,7 @@ def query_name(self, name: str) -> DataItem:
106106
107107
Returns
108108
-------
109-
match: DataItem
109+
match: Dataset
110110
"""
111111
xyz_flat_lower = {
112112
k.translate(QUERY_NAME_TRANSLATION).lower(): v
@@ -119,7 +119,7 @@ def query_name(self, name: str) -> DataItem:
119119
raise ValueError(f"No matching item found for the query '{name}'.")
120120

121121

122-
class DataItem(Bunch):
122+
class Dataset(Bunch):
123123
"""
124124
A dict with attribute-access and that
125125
can be called to update keys
@@ -136,18 +136,18 @@ def __init__(self, *args, **kwargs):
136136
msg = (
137137
f"The attributes {required} "
138138
f"are required to initialise "
139-
f"a `DataItem`. Please provide values for: "
139+
f"a `Dataset`. Please provide values for: "
140140
f'`{"`, `".join(missing)}`'
141141
)
142142
raise AttributeError(msg)
143143

144-
def __call__(self, **kwargs) -> DataItem:
145-
new = DataItem(self) # takes a copy preserving the class
144+
def __call__(self, **kwargs) -> Dataset:
145+
new = Dataset(self) # takes a copy preserving the class
146146
new.update(kwargs)
147147
return new
148148

149-
def copy(self, **kwargs) -> DataItem:
150-
new = DataItem(self) # takes a copy preserving the class
149+
def copy(self, **kwargs) -> Dataset:
150+
new = Dataset(self) # takes a copy preserving the class
151151
return new
152152

153153
def _repr_html_(self, inside=False):
@@ -162,7 +162,7 @@ def _repr_html_(self, inside=False):
162162
{style}
163163
<div class="xyz-wrap">
164164
<div class="xyz-header">
165-
<div class="xyz-obj">geodatasets.DataItem</div>
165+
<div class="xyz-obj">geodatasets.Dataset</div>
166166
<div class="xyz-name">{self.name}</div>
167167
</div>
168168
<div class="xyz-details">
@@ -187,9 +187,9 @@ def _load_json(f):
187187
item = data[item_name]
188188

189189
if "url" in item.keys():
190-
items[item_name] = DataItem(item)
190+
items[item_name] = Dataset(item)
191191
else:
192-
items[item_name] = Bunch({i: DataItem(item[i]) for i in item})
192+
items[item_name] = Bunch({i: Dataset(item[i]) for i in item})
193193

194194
return items
195195

geodatasets/tests/test_lib.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import pytest
22

3-
from geodatasets import Bunch, DataItem, data
3+
from geodatasets import Bunch, Dataset, data
44

55

66
@pytest.fixture
77
def data1():
8-
return DataItem(
8+
return Dataset(
99
url="https://myserver.com/data.zip",
1010
attribution="(C) geodatasets",
1111
name="my_public_data",
@@ -16,7 +16,7 @@ def data1():
1616

1717
@pytest.fixture
1818
def data2():
19-
return DataItem(
19+
return Dataset(
2020
url="https://myserver.com/?dghrtnkmjnkju",
2121
attribution="(C) geodatasets",
2222
name="my_public_data2",
@@ -43,18 +43,18 @@ def test_dir(data1):
4343
def test_expect_name_url_attribution():
4444

4545
with pytest.raises(AttributeError, match="`name`, `url`, `hash`, `filename`"):
46-
DataItem({})
46+
Dataset({})
4747
with pytest.raises(AttributeError, match="`url`, `hash`, `filename`"):
48-
DataItem({"name": "myname"})
48+
Dataset({"name": "myname"})
4949
with pytest.raises(AttributeError, match="`hash`, `filename`"):
50-
DataItem({"url": "my_url", "name": "my_name"})
50+
Dataset({"url": "my_url", "name": "my_name"})
5151

5252

5353
def test_html_repr(data1, data2):
5454
item_strings = [
5555
'<div class="xyz-wrap">',
5656
'<div class="xyz-header">',
57-
'<div class="xyz-obj">geodatasets.DataItem</div>',
57+
'<div class="xyz-obj">geodatasets.Dataset</div>',
5858
'<div class="xyz-name">my_public_data</div>',
5959
'<div class="xyz-details">',
6060
'<dl class="xyz-attrs">',
@@ -77,7 +77,7 @@ def test_html_repr(data1, data2):
7777
'<div class="xyz-name">2 items</div>',
7878
'<ul class="xyz-collapsible">',
7979
'<li class="xyz-child">',
80-
"<span>geodatasets.DataItem</span>",
80+
"<span>geodatasets.Dataset</span>",
8181
'<div class="xyz-inside">',
8282
]
8383

@@ -91,14 +91,14 @@ def test_html_repr(data1, data2):
9191

9292
def test_copy(data1):
9393
copied = data1.copy()
94-
assert isinstance(copied, DataItem)
94+
assert isinstance(copied, Dataset)
9595

9696

9797
def test_callable():
9898
# only testing the callable functionality to override a keyword, as we
9999
# cannot test the actual items that need an API key
100100
updated_item = data.ny.bb(hash="myhash")
101-
assert isinstance(updated_item, DataItem)
101+
assert isinstance(updated_item, Dataset)
102102
assert "url" in updated_item
103103
assert updated_item["hash"] == "myhash"
104104
# check that original item dict is not modified
@@ -130,7 +130,7 @@ def test_query_name():
130130

131131
for option in options:
132132
queried = data.query_name(option)
133-
assert isinstance(queried, DataItem)
133+
assert isinstance(queried, Dataset)
134134
assert queried.name == "ny.bb"
135135

136136
with pytest.raises(ValueError, match="No matching item found"):

0 commit comments

Comments
 (0)