Skip to content

Commit 5a15eb6

Browse files
committed
MOD: Rename get_shape to get_record_count
1 parent 90d4788 commit 5a15eb6

File tree

6 files changed

+25
-32
lines changed

6 files changed

+25
-32
lines changed

databento/common/bento.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime as dt
22
import io
33
import os.path
4-
from typing import TYPE_CHECKING, Any, BinaryIO, Callable, Dict, List, Optional, Tuple
4+
from typing import TYPE_CHECKING, Any, BinaryIO, Callable, Dict, List, Optional
55

66
import numpy as np
77
import pandas as pd
@@ -35,7 +35,7 @@ def __init__(self) -> None:
3535
self._limit: Optional[int] = None
3636
self._encoding: Optional[Encoding] = None
3737
self._compression: Optional[Compression] = None
38-
self._shape: Optional[Tuple[int, ...]] = None
38+
self._record_count: Optional[int] = None
3939

4040
def _check_metadata(self) -> None:
4141
if not self._metadata:
@@ -340,24 +340,20 @@ def compression(self) -> Compression:
340340
return self._compression
341341

342342
@property
343-
def shape(self) -> Tuple[int, ...]:
343+
def record_count(self) -> int:
344344
"""
345-
Return the shape of the data.
345+
Return the record count.
346346
347347
Returns
348348
-------
349-
Tuple[int, ...]
350-
The data shape.
349+
int
351350
352351
"""
353-
if self._shape is None:
352+
if self._record_count is None:
354353
self._check_metadata()
355-
self._shape = (
356-
self._metadata["record_count"],
357-
len(DBZ_STRUCT_MAP[self.schema]),
358-
)
354+
self._record_count = self._metadata["record_count"]
359355

360-
return self._shape
356+
return self._record_count
361357

362358
@property
363359
def mappings(self) -> Dict[str, List[Dict[str, Any]]]:

databento/historical/api/metadata.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def list_unit_prices(
241241
)
242242
return response.json()
243243

244-
def get_shape(
244+
def get_record_count(
245245
self,
246246
dataset: Union[Dataset, str],
247247
start: Union[pd.Timestamp, date, str, int],
@@ -251,11 +251,11 @@ def get_shape(
251251
encoding: Union[Encoding, str] = "dbz",
252252
stype_in: Optional[Union[SType, str]] = "native",
253253
limit: Optional[int] = None,
254-
) -> Tuple[int, ...]:
254+
) -> int:
255255
"""
256-
Request the shape of the time series data from Databento.
256+
Request the count of data records from Databento.
257257
258-
Makes a GET `/metadata.get_shape` HTTP request.
258+
Makes a GET `/metadata.get_record_count` HTTP request.
259259
260260
Parameters
261261
----------
@@ -282,8 +282,8 @@ def get_shape(
282282
283283
Returns
284284
-------
285-
Tuple[int, ...]
286-
The shape of the data expressed as size per dimension.
285+
int
286+
The count of records.
287287
288288
"""
289289
validate_enum(schema, Schema, "schema")
@@ -302,13 +302,12 @@ def get_shape(
302302
params.append(("limit", str(limit)))
303303

304304
response: Response = self._get(
305-
url=self._base_url + ".get_shape",
305+
url=self._base_url + ".get_record_count",
306306
params=params,
307307
basic_auth=True,
308308
)
309309

310-
values: List[int] = response.json()
311-
return tuple(values)
310+
return response.json()
312311

313312
def get_billable_size(
314313
self,
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Tuple
2-
31
import databento as db
42

53

@@ -9,7 +7,7 @@
97
key = "YOUR_API_KEY"
108
client = db.Historical(key=key)
119

12-
shape: Tuple[int, ...] = client.metadata.get_shape(
10+
count: int = client.metadata.get_record_count(
1311
dataset="GLBX.MDP3",
1412
symbols=["ESM2"],
1513
schema="mbo",
@@ -18,4 +16,4 @@
1816
encoding="csv",
1917
)
2018

21-
print(shape)
19+
print(count)

notebooks/quickstart.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,7 @@
446446
"\n",
447447
"All time series data requests include a metadata header with the following specifications:\n",
448448
"- The original query paramaters (these can be used to re-request the data)\n",
449-
"- Data shape\n",
450449
"- Symbology mappings\n",
451-
"- Instrument 'mini-definitions'"
452450
]
453451
},
454452
{
@@ -1737,4 +1735,4 @@
17371735
},
17381736
"nbformat": 4,
17391737
"nbformat_minor": 5
1740-
}
1738+
}

tests/test_historical_bento.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_bento_given_initial_nbytes_returns_expected_metadata(self) -> None:
126126
assert data.end == pd.Timestamp("2020-12-29 00:00:00+0000", tz="UTC")
127127
assert data.limit == 2
128128
assert data.compression == Compression.ZSTD
129-
assert data.shape == (2, 15)
129+
assert data.record_count == 2
130130
assert data.mappings == {
131131
"ESH1": [
132132
{

tests/test_historical_metadata.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ def test_list_unit_price_sends_expected_request(
211211
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
212212

213213
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
214-
def test_get_shape_sends_expected_request(self, mocker: MockerFixture) -> None:
214+
def test_get_record_count_sends_expected_request(
215+
self, mocker: MockerFixture
216+
) -> None:
215217
# Arrange
216218
mocked_get = mocker.patch("requests.get")
217219

218220
# Act
219-
self.client.metadata.get_shape(
221+
self.client.metadata.get_record_count(
220222
dataset="GLBX.MDP3",
221223
symbols=["ESH1"],
222224
schema="mbo",
@@ -229,7 +231,7 @@ def test_get_shape_sends_expected_request(self, mocker: MockerFixture) -> None:
229231
call = mocked_get.call_args.kwargs
230232
assert (
231233
call["url"]
232-
== f"https://hist.databento.com/v{db.API_VERSION}/metadata.get_shape"
234+
== f"https://hist.databento.com/v{db.API_VERSION}/metadata.get_record_count"
233235
)
234236
assert sorted(call["headers"].keys()) == ["accept", "user-agent"]
235237
assert call["headers"]["accept"] == "application/json"

0 commit comments

Comments
 (0)