Skip to content

Commit

Permalink
VER: Release 0.39.2
Browse files Browse the repository at this point in the history
See release notes.
  • Loading branch information
nmacholl authored Aug 13, 2024
2 parents f0dbdc9 + 5b59ef8 commit ee5d7bc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.39.2 - 2024-08-13

#### Enhancements
- Changed `corporate_actions.get_range(...)` to stream compressed zstd data

## 0.39.1 - 2024-08-13

#### Bug fixes
Expand Down
9 changes: 8 additions & 1 deletion databento/reference/api/corporate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

from collections.abc import Iterable
from datetime import date
from io import BytesIO
from io import StringIO

import pandas as pd
import zstandard
from databento_dbn import Compression
from databento_dbn import SType

from databento.common import API_VERSION
Expand Down Expand Up @@ -112,6 +115,7 @@ def get_range(
"events": ",".join(events) if events else None,
"countries": ",".join(countries) if countries else None,
"security_types": ",".join(security_types) if security_types else None,
"compression": str(Compression.ZSTD), # Always request zstd
}

response = self._post(
Expand All @@ -120,7 +124,10 @@ def get_range(
basic_auth=True,
)

df = pd.read_json(StringIO(response.text), lines=True)
decompressor = zstandard.ZstdDecompressor()
decompressed_content = decompressor.stream_reader(BytesIO(response.content)).read()

df = pd.read_json(StringIO(decompressed_content.decode()), lines=True)
if df.empty:
return df

Expand Down
2 changes: 1 addition & 1 deletion databento/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.39.1"
__version__ = "0.39.2"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "databento"
version = "0.39.1"
version = "0.39.2"
description = "Official Python client library for Databento"
authors = [
"Databento <[email protected]>",
Expand Down
12 changes: 7 additions & 5 deletions tests/test_reference_corporate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
import pytest
import requests
import zstandard
from databento.reference.client import Reference

from tests import TESTS_ROOT
Expand Down Expand Up @@ -77,7 +78,7 @@ def test_corporate_actions_get_range_sends_expected_request(
) -> None:
# Arrange
mock_response = MagicMock()
mock_response.text = "{}"
mock_response.content = zstandard.compress(b"{}")
mock_response.__enter__.return_value = mock_response
mock_response.__exit__ = MagicMock()
monkeypatch.setattr(requests, "post", mock_post := MagicMock(return_value=mock_response))
Expand Down Expand Up @@ -110,6 +111,7 @@ def test_corporate_actions_get_range_sends_expected_request(
"events": expected_events,
"countries": expected_countries,
"security_types": expected_security_types,
"compression": "zstd",
}
assert call["timeout"] == (100, 100)
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
Expand All @@ -122,7 +124,7 @@ def test_corporate_actions_get_range_response_parsing_as_pit(
# Arrange
data_path = Path(TESTS_ROOT) / "data" / "REFERENCE" / "test_data.corporate-actions.ndjson"
mock_response = MagicMock()
mock_response.text = data_path.read_text()
mock_response.content = zstandard.compress(data_path.read_bytes())
mock_response.__enter__.return_value = mock_response
mock_response.__exit__ = MagicMock()
monkeypatch.setattr(requests, "post", MagicMock(return_value=mock_response))
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_corporate_actions_get_range_response(
# Arrange
data_path = Path(TESTS_ROOT) / "data" / "REFERENCE" / "test_data.corporate-actions-pit.ndjson"
mock_response = MagicMock()
mock_response.text = data_path.read_text()
mock_response.content = zstandard.compress(data_path.read_bytes())
mock_response.__enter__.return_value = mock_response
mock_response.__exit__ = MagicMock()
monkeypatch.setattr(requests, "post", MagicMock(return_value=mock_response))
Expand All @@ -178,7 +180,7 @@ def test_corporate_actions_get_range_with_ts_record_index(
# Arrange
data_path = Path(TESTS_ROOT) / "data" / "REFERENCE" / "test_data.corporate-actions.ndjson"
mock_response = MagicMock()
mock_response.text = data_path.read_text()
mock_response.content = zstandard.compress(data_path.read_bytes())
mock_response.__enter__.return_value = mock_response
mock_response.__exit__ = MagicMock()
monkeypatch.setattr(requests, "post", MagicMock(return_value=mock_response))
Expand Down Expand Up @@ -212,7 +214,7 @@ def test_corporate_actions_get_range_without_flattening(
# Arrange
data_path = Path(TESTS_ROOT) / "data" / "REFERENCE" / "test_data.corporate-actions.ndjson"
mock_response = MagicMock()
mock_response.text = data_path.read_text()
mock_response.content = zstandard.compress(data_path.read_bytes())
mock_response.__enter__.return_value = mock_response
mock_response.__exit__ = MagicMock()
monkeypatch.setattr(requests, "post", MagicMock(return_value=mock_response))
Expand Down

0 comments on commit ee5d7bc

Please sign in to comment.