Skip to content

Commit 63ce2a3

Browse files
authored
VER: Release 0.27.0
2 parents 18f45c2 + f5ddca8 commit 63ce2a3

File tree

15 files changed

+141
-78
lines changed

15 files changed

+141
-78
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## 0.27.0 - 2024-01-23
4+
5+
#### Enhancements
6+
- Added `Session.session_id` property which will contain the numerical session ID once a live session has been authenticated
7+
- Upgraded `databento-dbn` to 0.15.1
8+
9+
#### Breaking changes
10+
- Renamed `DatabentoLiveProtocol.started` to `DatabentoLiveProtocol.is_started` which now returns a bool instead of an `asyncio.Event`
11+
12+
#### Bug fixes
13+
- Fixed an issue where an error message from the live gateway would not properly raise an exception if the connection closed before `Live.start` was called
14+
315
## 0.26.0 - 2024-01-16
416

517
This release adds support for transcoding DBN data into Apache parquet.
@@ -246,7 +258,7 @@ This release includes updates to the fields in text encodings (CSV and JSON), yo
246258
## 0.14.0 - 2023-06-14
247259

248260
#### Enhancements
249-
- Added `DatatbentoLiveProtocol` class
261+
- Added `DatabentoLiveProtocol` class
250262
- Added `metadata` property to `Live`
251263
- Added support for reusing a `Live` client to reconnect
252264
- Added support for emitting warnings in API response headers

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The library is fully compatible with the latest distribution of Anaconda 3.8 and
3232
The minimum dependencies as found in the `pyproject.toml` are also listed below:
3333
- python = "^3.8"
3434
- aiohttp = "^3.8.3"
35-
- databento-dbn = "0.15.0"
35+
- databento-dbn = "0.15.1"
3636
- numpy= ">=1.23.5"
3737
- pandas = ">=1.5.3"
3838
- pyarrow = ">=13.0.0"

databento/common/dbnstore.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class FileDataSource(DataSource):
132132
The name of the file.
133133
nbytes : int
134134
The size of the data in bytes; equal to the file size.
135-
path : PathLike or str
135+
path : PathLike[str] or str
136136
The path of the file.
137137
reader : IO[bytes]
138138
A `BufferedReader` for this file-backed data.
@@ -634,7 +634,7 @@ def from_file(cls, path: PathLike[str] | str) -> DBNStore:
634634
635635
Parameters
636636
----------
637-
path : Path or str
637+
path : PathLike[str] or str
638638
The path to read from.
639639
640640
Returns
@@ -695,7 +695,7 @@ def replay(self, callback: Callable[[Any], None]) -> None:
695695
def request_full_definitions(
696696
self,
697697
client: Historical,
698-
path: Path | str | None = None,
698+
path: PathLike[str] | str | None = None,
699699
) -> DBNStore:
700700
"""
701701
Request full instrument definitions based on the metadata properties.
@@ -706,7 +706,7 @@ def request_full_definitions(
706706
----------
707707
client : Historical
708708
The historical client to use for the request (contains the API key).
709-
path : Path or str, optional
709+
path : PathLike[str] or str, optional
710710
The path to stream the data to on disk (will then return a `DBNStore`).
711711
712712
Returns
@@ -768,7 +768,7 @@ def request_symbology(self, client: Historical) -> dict[str, Any]:
768768

769769
def to_csv(
770770
self,
771-
path: Path | str,
771+
path: PathLike[str] | str,
772772
pretty_px: bool = True,
773773
pretty_ts: bool = True,
774774
map_symbols: bool = True,
@@ -780,7 +780,7 @@ def to_csv(
780780
781781
Parameters
782782
----------
783-
path : Path or str
783+
path : PathLike[str] or str
784784
The file path to write to.
785785
pretty_px : bool, default True
786786
If all price columns should be converted from `int` to `float` at
@@ -922,7 +922,7 @@ def to_df(
922922

923923
def to_parquet(
924924
self,
925-
path: Path | str,
925+
path: PathLike[str] | str,
926926
price_type: Literal["fixed", "float"] = "float",
927927
pretty_ts: bool = True,
928928
map_symbols: bool = True,
@@ -995,13 +995,13 @@ def to_parquet(
995995
if writer is not None:
996996
writer.close()
997997

998-
def to_file(self, path: Path | str) -> None:
998+
def to_file(self, path: PathLike[str] | str) -> None:
999999
"""
10001000
Write the data to a DBN file at the given path.
10011001
10021002
Parameters
10031003
----------
1004-
path : str
1004+
path : PathLike[str] or str
10051005
The file path to write to.
10061006
10071007
Raises
@@ -1021,7 +1021,7 @@ def to_file(self, path: Path | str) -> None:
10211021

10221022
def to_json(
10231023
self,
1024-
path: Path | str,
1024+
path: PathLike[str] | str,
10251025
pretty_px: bool = True,
10261026
pretty_ts: bool = True,
10271027
map_symbols: bool = True,
@@ -1033,7 +1033,7 @@ def to_json(
10331033
10341034
Parameters
10351035
----------
1036-
path : Path or str
1036+
path : PathLike[str] or str
10371037
The file path to write to.
10381038
pretty_px : bool, default True
10391039
If all price columns should be converted from `int` to `float` at
@@ -1319,7 +1319,7 @@ def __next__(self) -> np.ndarray[Any, Any]:
13191319
except ValueError:
13201320
raise BentoError(
13211321
"DBN file is truncated or contains an incomplete record",
1322-
)
1322+
) from None
13231323

13241324

13251325
class DataFrameIterator:

databento/common/symbology.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class MappingInterval(NamedTuple):
4343

4444

4545
def _validate_path_pair(
46-
in_file: Path | PathLike[str] | str,
47-
out_file: Path | PathLike[str] | str | None,
46+
in_file: PathLike[str] | str,
47+
out_file: PathLike[str] | str | None,
4848
) -> tuple[Path, Path]:
4949
in_file_valid = Path(in_file)
5050

@@ -74,22 +74,22 @@ def _validate_path_pair(
7474

7575

7676
def map_symbols_csv(
77-
symbology_file: Path | PathLike[str] | str,
78-
csv_file: Path | PathLike[str] | str,
79-
out_file: Path | PathLike[str] | str | None = None,
77+
symbology_file: PathLike[str] | str,
78+
csv_file: PathLike[str] | str,
79+
out_file: PathLike[str] | str | None = None,
8080
) -> Path:
8181
"""
8282
Use a `symbology.json` file to map a symbols column onto an existing CSV
8383
file. The result is written to `out_file`.
8484
8585
Parameters
8686
----------
87-
symbology_file: Path | PathLike[str] | str
87+
symbology_file: PathLike[str] | str
8888
Path to a `symbology.json` file to use as a symbology source.
89-
csv_file: Path | PathLike[str] | str
89+
csv_file: PathLike[str] | str
9090
Path to a CSV file that contains encoded DBN data; must contain
9191
a `ts_recv` or `ts_event` and `instrument_id` column.
92-
out_file: Path | PathLike[str] | str (optional)
92+
out_file: PathLike[str] | str (optional)
9393
Path to a file to write results to. If unspecified, `_mapped` will be
9494
appended to the `csv_file` name.
9595
@@ -119,21 +119,21 @@ def map_symbols_csv(
119119

120120

121121
def map_symbols_json(
122-
symbology_file: Path | PathLike[str] | str,
123-
json_file: Path | PathLike[str] | str,
124-
out_file: Path | PathLike[str] | str | None = None,
122+
symbology_file: PathLike[str] | str,
123+
json_file: PathLike[str] | str,
124+
out_file: PathLike[str] | str | None = None,
125125
) -> Path:
126126
"""
127127
Use a `symbology.json` file to insert a symbols key into records of an
128128
existing JSON file. The result is written to `out_file`.
129129
130130
Parameters
131131
----------
132-
symbology_file: Path | PathLike[str] | str
132+
symbology_file: PathLike[str] | str
133133
Path to a `symbology.json` file to use as a symbology source.
134-
json_file: Path | PathLike[str] | str
134+
json_file: PathLike[str] | str
135135
Path to a JSON file that contains encoded DBN data.
136-
out_file: Path | PathLike[str] | str (optional)
136+
out_file: PathLike[str] | str (optional)
137137
Path to a file to write results to. If unspecified, `_mapped` will be
138138
appended to the `json_file` name.
139139
@@ -243,7 +243,9 @@ def insert_metadata(self, metadata: Metadata) -> None:
243243
return
244244

245245
stype_in = SType(metadata.stype_in) if metadata.stype_in is not None else None
246-
stype_out = SType(metadata.stype_out) if metadata.stype_out is not None else None
246+
stype_out = (
247+
SType(metadata.stype_out) if metadata.stype_out is not None else None
248+
)
247249

248250
for symbol_in, entries in metadata.mappings.items():
249251
for entry in entries:
@@ -395,19 +397,19 @@ def insert_json(
395397

396398
def map_symbols_csv(
397399
self,
398-
csv_file: Path | PathLike[str] | str,
399-
out_file: Path | PathLike[str] | str | None = None,
400+
csv_file: PathLike[str] | str,
401+
out_file: PathLike[str] | str | None = None,
400402
) -> Path:
401403
"""
402404
Use the loaded symbology data to map a symbols column onto an existing
403405
CSV file. The result is written to `out_file`.
404406
405407
Parameters
406408
----------
407-
csv_file: Path | PathLike[str] | str
409+
csv_file: PathLike[str] | str
408410
Path to a CSV file that contains encoded DBN data; must contain
409411
a `ts_recv` or `ts_event` and `instrument_id` column.
410-
out_file: Path | PathLike[str] | str (optional)
412+
out_file: PathLike[str] | str (optional)
411413
Path to a file to write results to. If unspecified, `_mapped` will be
412414
appended to the `csv_file` name.
413415
@@ -474,18 +476,18 @@ def map_symbols_csv(
474476

475477
def map_symbols_json(
476478
self,
477-
json_file: Path | PathLike[str] | str,
478-
out_file: Path | PathLike[str] | str | None = None,
479+
json_file: PathLike[str] | str,
480+
out_file: PathLike[str] | str | None = None,
479481
) -> Path:
480482
"""
481483
Use the loaded symbology data to insert a symbols key into records of
482484
an existing JSON file. The result is written to `out_file`.
483485
484486
Parameters
485487
----------
486-
json_file: Path | PathLike[str] | str
488+
json_file: PathLike[str] | str
487489
Path to a JSON file that contains encoded DBN data.
488-
out_file: Path | PathLike[str] | str (optional)
490+
out_file: PathLike[str] | str (optional)
489491
Path to a file to write results to. If unspecified, `_mapped` will be
490492
appended to the `json_file` name.
491493

databento/common/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def validate_path(value: PathLike[str] | str, param: str) -> Path:
1818
1919
Parameters
2020
----------
21-
value: PathLike or str
21+
value: PathLike[str] or str
2222
The value to validate.
2323
param : str
2424
The name of the parameter being validated (for any error message).
@@ -49,7 +49,7 @@ def validate_file_write_path(value: PathLike[str] | str, param: str) -> Path:
4949
5050
Parameters
5151
----------
52-
value: PathLike or str
52+
value: PathLike[str] or str
5353
The value to validate.
5454
param : str
5555
The name of the parameter being validated (for any error message).

databento/historical/api/batch.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from databento.common.enums import Delivery
2121
from databento.common.enums import Packaging
2222
from databento.common.enums import SplitDuration
23+
from databento.common.error import BentoError
2324
from databento.common.parsing import datetime_to_string
2425
from databento.common.parsing import optional_datetime_to_string
2526
from databento.common.parsing import optional_symbols_list_to_list
@@ -252,7 +253,7 @@ def download(
252253
253254
Parameters
254255
----------
255-
output_dir: PathLike or str
256+
output_dir: PathLike[str] or str
256257
The directory to download the file(s) to.
257258
job_id : str
258259
The batch job identifier.
@@ -371,8 +372,11 @@ def _download_file(
371372

372373
logger.debug("Starting download of file %s", output_path.name)
373374
with open(output_path, mode=mode) as f:
374-
for chunk in response.iter_content(chunk_size=None):
375-
f.write(chunk)
375+
try:
376+
for chunk in response.iter_content(chunk_size=None):
377+
f.write(chunk)
378+
except Exception as exc:
379+
raise BentoError(f"Error downloading file: {exc}") from None
376380
logger.debug("Download of %s completed", output_path.name)
377381

378382
async def download_async(
@@ -393,7 +397,7 @@ async def download_async(
393397
394398
Parameters
395399
----------
396-
output_dir: PathLike or str
400+
output_dir: PathLike[str] or str
397401
The directory to download the file(s) to.
398402
job_id : str
399403
The batch job identifier.
@@ -512,9 +516,12 @@ async def _download_file_async(
512516

513517
logger.debug("Starting async download of file %s", output_path.name)
514518
with open(output_path, mode=mode) as f:
515-
async for chunk in response.content.iter_chunks():
516-
data: bytes = chunk[0]
517-
f.write(data)
519+
try:
520+
async for chunk in response.content.iter_chunks():
521+
data: bytes = chunk[0]
522+
f.write(data)
523+
except Exception as exc:
524+
raise BentoError(f"Error downloading file: {exc}") from None
518525
logger.debug("Download of %s completed", output_path.name)
519526

520527
def _get_file_download_headers_and_mode(

databento/historical/api/timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_range(
8080
The output symbology type to resolve to.
8181
limit : int, optional
8282
The maximum number of records to return. If `None` then no limit.
83-
path : PathLike or str, optional
83+
path : PathLike[str] or str, optional
8484
The file path to stream the data to on disk (will then return a `DBNStore`).
8585
8686
Returns
@@ -177,7 +177,7 @@ async def get_range_async(
177177
The output symbology type to resolve to.
178178
limit : int, optional
179179
The maximum number of records to return. If `None` then no limit.
180-
path : PathLike or str, optional
180+
path : PathLike[str] or str, optional
181181
The file path to stream the data to on disk (will then return a `DBNStore`).
182182
183183
Returns

databento/historical/http.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from databento.common.dbnstore import DBNStore
1919
from databento.common.error import BentoClientError
2020
from databento.common.error import BentoDeprecationWarning
21+
from databento.common.error import BentoError
2122
from databento.common.error import BentoServerError
2223
from databento.common.error import BentoWarning
2324
from databento.common.system import USER_AGENT
@@ -132,8 +133,11 @@ def _stream(
132133
else:
133134
writer = open(path, "x+b")
134135

135-
for chunk in response.iter_content(chunk_size=None):
136-
writer.write(chunk)
136+
try:
137+
for chunk in response.iter_content(chunk_size=None):
138+
writer.write(chunk)
139+
except Exception as exc:
140+
raise BentoError(f"Error streaming response: {exc}") from None
137141

138142
if path is None:
139143
writer.seek(0)
@@ -169,8 +173,11 @@ async def _stream_async(
169173
else:
170174
writer = open(path, "x+b")
171175

172-
async for chunk in response.content.iter_chunks():
173-
writer.write(chunk[0])
176+
try:
177+
async for chunk in response.content.iter_chunks():
178+
writer.write(chunk[0])
179+
except Exception as exc:
180+
raise BentoError(f"Error streaming response: {exc}") from None
174181

175182
if path is None:
176183
writer.seek(0)

0 commit comments

Comments
 (0)