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

VER: Release 0.43.0 #74

Merged
merged 7 commits into from
Oct 8, 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
name: build - Python ${{ matrix.python-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.43.0 - 2024-10-09

This release drops support for Python 3.8 which has reached end-of-life.

#### Enhancements
- Added `PriceType` enum for validation of `price_type` parameter in `DBNStore.to_df`
- Upgraded `databento-dbn` to 0.22.1

#### Bug fixes
- Fixed return type hint for `metadata.get_dataset_condition`

#### Breaking changes
- Removed support for Python 3.8 due to end of life

## 0.42.0 - 2024-09-23

#### Enhancements
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# databento-python

[![test](https://github.com/databento/databento-python/actions/workflows/test.yml/badge.svg?branch=dev)](https://github.com/databento/databento-python/actions/workflows/test.yml)
![python](https://img.shields.io/badge/python-3.8+-blue.svg)
![python](https://img.shields.io/badge/python-3.9+-blue.svg)
[![pypi-version](https://img.shields.io/pypi/v/databento)](https://pypi.org/project/databento)
[![license](https://img.shields.io/github/license/databento/databento-python?color=blue)](./LICENSE)
[![code-style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Expand All @@ -28,16 +28,16 @@ You can find our full client API reference on the [Historical Reference](https:/
[Examples](https://databento.com/docs/examples?historical=python&live=python) section for various tutorials and code samples.

## Requirements
The library is fully compatible with the latest distribution of Anaconda 3.8 and above.
The library is fully compatible with the latest distribution of Anaconda 3.9 and above.
The minimum dependencies as found in the `pyproject.toml` are also listed below:
- python = "^3.8"
- python = "^3.9"
- aiohttp = "^3.8.3"
- databento-dbn = "0.20.1"
- databento-dbn = "0.22.1"
- numpy= ">=1.23.5"
- pandas = ">=1.5.3"
- pip-system-certs = ">=4.0" (Windows only)
- pyarrow = ">=13.0.0"
- requests = ">=2.24.0"
- requests = ">=2.25.1"
- zstandard = ">=0.21.0"

## Installation
Expand Down
7 changes: 3 additions & 4 deletions databento/common/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

from typing import Final

import numpy as np
from databento_dbn import BBOMsg
from databento_dbn import CBBOMsg
from databento_dbn import CMBP1Msg
from databento_dbn import ImbalanceMsg
from databento_dbn import InstrumentDefMsg
from databento_dbn import InstrumentDefMsgV1
Expand Down Expand Up @@ -44,7 +43,7 @@
Schema.STATUS: StatusMsg,
Schema.TBBO: MBP1Msg,
Schema.TRADES: TradeMsg,
Schema.CBBO: CBBOMsg,
Schema.CMBP_1: CMBP1Msg,
Schema.CBBO_1S: CBBOMsg,
Schema.CBBO_1M: CBBOMsg,
Schema.TCBBO: CBBOMsg,
Expand All @@ -66,7 +65,7 @@
Schema.STATUS: StatusMsg,
Schema.TBBO: MBP1Msg,
Schema.TRADES: TradeMsg,
Schema.CBBO: CBBOMsg,
Schema.CMBP_1: CMBP1Msg,
Schema.CBBO_1S: CBBOMsg,
Schema.CBBO_1M: CBBOMsg,
Schema.TCBBO: CBBOMsg,
Expand Down
18 changes: 10 additions & 8 deletions databento/common/dbnstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from databento.common.constants import DEFINITION_TYPE_MAX_MAP
from databento.common.constants import SCHEMA_STRUCT_MAP
from databento.common.constants import SCHEMA_STRUCT_MAP_V1
from databento.common.enums import PriceType
from databento.common.error import BentoError
from databento.common.error import BentoWarning
from databento.common.symbology import InstrumentMap
Expand Down Expand Up @@ -848,7 +849,7 @@ def to_csv(
@overload
def to_df(
self,
price_type: Literal["fixed", "float", "decimal"] = ...,
price_type: PriceType | str = ...,
pretty_ts: bool = ...,
map_symbols: bool = ...,
schema: Schema | str | None = ...,
Expand All @@ -859,7 +860,7 @@ def to_df(
@overload
def to_df(
self,
price_type: Literal["fixed", "float", "decimal"] = ...,
price_type: PriceType | str = ...,
pretty_ts: bool = ...,
map_symbols: bool = ...,
schema: Schema | str | None = ...,
Expand All @@ -869,7 +870,7 @@ def to_df(

def to_df(
self,
price_type: Literal["fixed", "float", "decimal"] = "float",
price_type: PriceType | str = PriceType.FLOAT,
pretty_ts: bool = True,
map_symbols: bool = True,
schema: Schema | str | None = None,
Expand All @@ -883,7 +884,7 @@ def to_df(

Parameters
----------
price_type : str, default "float"
price_type : PriceType or str, default "float"
The price type to use for price fields.
If "fixed", prices will have a type of `int` in fixed decimal format; each unit representing 1e-9 or 0.000000001.
If "float", prices will have a type of `float`.
Expand Down Expand Up @@ -918,6 +919,7 @@ def to_df(
If the DBN schema is unspecified and cannot be determined.

"""
price_type = validate_enum(price_type, PriceType, "price_type")
schema = validate_maybe_enum(schema, Schema, "schema")

if isinstance(tz, Default):
Expand Down Expand Up @@ -1422,7 +1424,7 @@ def __init__(
struct_type: type[DBNRecord],
instrument_map: InstrumentMap,
tz: pytz.BaseTzInfo,
price_type: Literal["fixed", "float", "decimal"] = "float",
price_type: PriceType = PriceType.FLOAT,
pretty_ts: bool = True,
map_symbols: bool = True,
):
Expand Down Expand Up @@ -1499,16 +1501,16 @@ def _format_timezone(self, df: pd.DataFrame) -> None:
def _format_px(
self,
df: pd.DataFrame,
price_type: Literal["fixed", "float", "decimal"],
price_type: PriceType,
) -> None:
px_fields = self._struct_type._price_fields

if price_type == "decimal":
if price_type == PriceType.DECIMAL:
df[px_fields] = (
df[px_fields].replace(UNDEF_PRICE, np.nan).applymap(decimal.Decimal)
/ FIXED_PRICE_SCALE
)
elif price_type == "float":
elif price_type == PriceType.FLOAT:
df[px_fields] = df[px_fields].replace(UNDEF_PRICE, np.nan) / FIXED_PRICE_SCALE
else:
return # do nothing
Expand Down
16 changes: 16 additions & 0 deletions databento/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,21 @@ class RecordFlags(StringyMixin, IntFlag): # type: ignore
@unique
@coercible
class ReconnectPolicy(StringyMixin, str, Enum):
"""
Live session reconnection policy.
"""

NONE = "none"
RECONNECT = "reconnect"


@unique
@coercible
class PriceType(StringyMixin, str, Enum):
"""
Price type for DataFrame price fields.
"""

FIXED = "fixed"
FLOAT = "float"
DECIMAL = "decimal"
2 changes: 0 additions & 2 deletions databento/common/iterator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import itertools
from collections.abc import Iterable
from typing import TypeVar
Expand Down
1 change: 1 addition & 0 deletions databento/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DBNRecord = Union[
databento_dbn.BBOMsg,
databento_dbn.CBBOMsg,
databento_dbn.CMBP1Msg,
databento_dbn.MBOMsg,
databento_dbn.MBP1Msg,
databento_dbn.MBP10Msg,
Expand Down
4 changes: 2 additions & 2 deletions databento/historical/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_dataset_condition(
dataset: Dataset | str,
start_date: date | str | None = None,
end_date: date | str | None = None,
) -> dict[str, Any]:
) -> list[dict[str, str]]:
"""
Get the per date dataset conditions from Databento.

Expand All @@ -209,7 +209,7 @@ def get_dataset_condition(

Returns
-------
dict[str, Any]
list[dict[str, str]]

"""
params: list[tuple[str, str | None]] = [
Expand Down
2 changes: 1 addition & 1 deletion notebooks/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ repository = "https://github.com/databento/databento-python"
"Bug Tracker" = "https://github.com/databento/databento-python/issues"

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.9"
aiohttp = [
{version = "^3.8.3", python = "<3.12"},
{version = "^3.9.0", python = "^3.12"}
]
databento-dbn = "0.20.1"
databento-dbn = "0.22.1"
numpy = [
{version = ">=1.23.5", python = "<3.12"},
{version = "^1.26.0", python = "^3.12"}
{version = ">=1.26.0", python = "^3.12"}
]
pandas = ">=1.5.3"
pip-system-certs = {version=">=4.0", markers="platform_system == 'Windows'"}
pyarrow = ">=13.0.0"
requests = ">=2.24.0"
requests = ">=2.25.1"
zstandard = ">=0.21.0"

[tool.poetry.group.dev.dependencies]
Expand All @@ -63,7 +63,7 @@ build-backend = "poetry.core.masonry.api"
line_length = 100

[tool.mypy]
python_version = 3.8
python_version = 3.9
disallow_untyped_defs = true
disallow_any_generics = true
disallow_subclassing_any = true
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Pytest fixtures.
"""

from __future__ import annotations

import asyncio
import logging
import pathlib
Expand Down
2 changes: 0 additions & 2 deletions tests/mockliveserver/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import argparse
import asyncio
import logging
Expand Down
2 changes: 0 additions & 2 deletions tests/mockliveserver/fixture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import asyncio
import contextlib
import os
Expand Down
2 changes: 1 addition & 1 deletion tests/mockliveserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import logging
import random
import string
from collections.abc import Generator
from collections.abc import Mapping
from functools import singledispatchmethod
from io import BytesIO
from io import FileIO
from typing import Any
from typing import Final
from typing import Generator

from databento.common import cram
from databento.common.publishers import Dataset
Expand Down
4 changes: 2 additions & 2 deletions tests/mockliveserver/source.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections.abc import Generator
from collections.abc import Iterator
from pathlib import Path
from typing import IO
from typing import Final
from typing import Generator
from typing import Iterator
from typing import Protocol

import zstandard
Expand Down
2 changes: 0 additions & 2 deletions tests/test_common_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Unit tests for databento.common.enums.
"""

from __future__ import annotations

from enum import Enum
from enum import Flag
from itertools import combinations
Expand Down
2 changes: 0 additions & 2 deletions tests/test_common_iterator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from collections.abc import Iterable

import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common_symbology.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def create_symbol_mapping_message(
SymbolMappingMsg

"""
return SymbolMappingMsg( # type: ignore [call-arg]
return SymbolMappingMsg(
publisher_id=publisher_id,
instrument_id=instrument_id,
ts_event=ts_event,
Expand Down
14 changes: 12 additions & 2 deletions tests/test_historical_bento.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import collections
import datetime as dt
import decimal
Expand Down Expand Up @@ -648,6 +646,18 @@ def test_to_df_with_price_type_handles_null(
assert all(np.isnan(df_pretty["strike_price"]))


def test_to_df_with_price_type_invalid(
test_data: Callable[[Dataset, Schema], bytes],
) -> None:
# Arrange
stub_data = test_data(Dataset.GLBX_MDP3, Schema.DEFINITION)
data = DBNStore.from_bytes(data=stub_data)

# Act, Assert
with pytest.raises(ValueError):
data.to_df(price_type="US/Eastern")


@pytest.mark.parametrize(
"dataset",
[
Expand Down
2 changes: 0 additions & 2 deletions tests/test_historical_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from unittest.mock import AsyncMock
from unittest.mock import MagicMock

Expand Down
1 change: 1 addition & 0 deletions tests/test_live_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ async def test_live_stream_with_reuse(
"cbbo-1s",
"cbbo-1m",
"tcbbo",
"cmbp-1",
"bbo-1s",
"bbo-1m",
):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Tests specific to releasing a version of databento-python.
"""

from __future__ import annotations

import operator
import re
from datetime import date
Expand Down
Loading