Skip to content

Commit f7b8ee6

Browse files
committed
DEL: Delete warning for size and stype deprecation
1 parent 7b08638 commit f7b8ee6

File tree

6 files changed

+28
-261
lines changed

6 files changed

+28
-261
lines changed

databento/common/enums.py

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import warnings
2-
from enum import Enum, EnumMeta, Flag, IntFlag, unique
3-
from typing import Any, Callable, Iterable, Type, TypeVar, Union
1+
from enum import Enum, Flag, IntFlag, unique
2+
from typing import Callable, Type, TypeVar, Union
43

5-
from databento.live.dbn import DBNRecord
64
from databento_dbn import (
75
ImbalanceMsg,
86
InstrumentDefMsg,
@@ -14,6 +12,7 @@
1412
TradeMsg,
1513
)
1614

15+
from databento.live.dbn import DBNRecord
1716

1817
M = TypeVar("M", bound=Enum)
1918

@@ -90,46 +89,6 @@ def coerced_new(enum: Type[M], value: object) -> M:
9089
return enum_type
9190

9291

93-
class DeprecatedAccess(EnumMeta):
94-
"""
95-
runs a user-specified function whenever member is accessed
96-
"""
97-
98-
def __getattribute__(cls, name: str) -> object:
99-
obj = super().__getattribute__(name)
100-
if isinstance(obj, Enum) and obj._on_access: # type: ignore
101-
obj._on_access() # type: ignore
102-
return obj
103-
104-
def __getitem__(cls, name: str, *_: Iterable[Any]) -> object: # type: ignore
105-
member: Any = super().__getitem__(name)
106-
if member._on_access:
107-
member._on_access()
108-
return member
109-
110-
def __call__( # type: ignore
111-
cls,
112-
value: str,
113-
names=None,
114-
*,
115-
module=None,
116-
qualname=None,
117-
type=None,
118-
start=1,
119-
) -> object:
120-
obj = super().__call__(
121-
value,
122-
names,
123-
module=module,
124-
qualname=qualname,
125-
type=type,
126-
start=start,
127-
)
128-
if isinstance(obj, Enum) and obj._on_access:
129-
obj._on_access()
130-
return obj
131-
132-
13392
class StringyMixin:
13493
"""
13594
Mixin class for overloading __str__ on Enum types.
@@ -273,46 +232,16 @@ class Delivery(StringyMixin, str, Enum):
273232
DISK = "disk"
274233

275234

276-
def deprecated_enum(old_value: str, new_value: str) -> str:
277-
warnings.warn(
278-
f"{old_value} is deprecated to {new_value}",
279-
category=DeprecationWarning,
280-
stacklevel=3, # This makes the error happen in user code
281-
)
282-
return new_value
283-
284-
285235
@unique
286236
@coercible
287-
class SType(StringyMixin, str, Enum, metaclass=DeprecatedAccess):
237+
class SType(StringyMixin, str, Enum):
288238
"""Represents a symbology type."""
289239

290-
PRODUCT_ID = "product_id", "instrument_id" # Deprecated for `instrument_id`
291-
NATIVE = "native", "raw_symbol" # Deprecated for `raw_symbol`
292-
SMART = "smart", "parent", "continuous" # Deprecated for `parent` and `continuous`
293240
INSTRUMENT_ID = "instrument_id"
294241
RAW_SYMBOL = "raw_symbol"
295242
PARENT = "parent"
296243
CONTINUOUS = "continuous"
297244

298-
def __new__(cls, value: str, *args: Iterable[str]) -> "SType":
299-
variant = super().__new__(cls, value)
300-
variant._value_ = value
301-
variant.__args = args # type: ignore
302-
variant._on_access = variant.__deprecated if args else None # type: ignore
303-
return variant
304-
305-
def __eq__(self, other: object) -> bool:
306-
return str(self).lower() == str(other).lower()
307-
308-
def __deprecated(self) -> None:
309-
other_values = " or ".join(self.__args) # type: ignore
310-
warnings.warn(
311-
f"SType of {self.value} is deprecated; use {other_values}",
312-
category=DeprecationWarning,
313-
stacklevel=3,
314-
)
315-
316245

317246
@unique
318247
@coercible

databento/common/parsing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ def _(symbols: str, stype_in: SType) -> str:
142142
symbol_list = symbols.strip().strip(",").split(",")
143143
return ",".join(map(symbol_to_string, symbol_list))
144144

145-
# TODO(cs): Temporary mapping until past stype rename deprecation period
146-
if stype_in in (SType.PARENT, SType.CONTINUOUS) or stype_in == "smart":
145+
if stype_in in (SType.PARENT, SType.CONTINUOUS):
147146
return validate_smart_symbol(symbols)
148147
return symbols.strip().upper()
149148

databento/historical/api/timeseries.py

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import warnings
43
from datetime import date
54
from io import BufferedIOBase
65
from io import BytesIO
@@ -16,20 +15,15 @@
1615
from databento.common.enums import Encoding
1716
from databento.common.enums import Schema
1817
from databento.common.enums import SType
19-
from databento.common.error import BentoWarning
2018
from databento.common.parsing import datetime_to_string
2119
from databento.common.parsing import optional_datetime_to_string
2220
from databento.common.parsing import optional_symbols_list_to_string
2321
from databento.common.validation import validate_enum
2422
from databento.common.validation import validate_semantic_string
2523
from databento.historical.api import API_VERSION
26-
from databento.historical.api.metadata import MetadataHttpAPI
2724
from databento.historical.http import BentoHttpAPI
2825

2926

30-
WARN_REQUEST_SIZE: int = 5 * 10**9 # 5 GB
31-
32-
3327
class TimeSeriesHttpAPI(BentoHttpAPI):
3428
"""
3529
Provides request methods for the time series HTTP API endpoints.
@@ -125,16 +119,6 @@ def get_range(
125119
if limit is not None:
126120
params.append(("limit", str(limit)))
127121

128-
self._pre_check_data_size(
129-
dataset=dataset,
130-
stype_in=stype_in_valid,
131-
symbols=symbols_list,
132-
schema=schema_valid,
133-
start=start_valid,
134-
end=end_valid,
135-
limit=limit,
136-
)
137-
138122
if path is not None:
139123
writer: BufferedIOBase = open(path, "x+b")
140124
else:
@@ -268,16 +252,6 @@ async def get_range_async(
268252
if limit is not None:
269253
params.append(("limit", str(limit)))
270254

271-
self._pre_check_data_size(
272-
dataset=dataset,
273-
stype_in=stype_in_valid,
274-
symbols=symbols_list,
275-
schema=schema_valid,
276-
start=start_valid,
277-
end=end_valid,
278-
limit=limit,
279-
)
280-
281255
if path is not None:
282256
writer: BufferedIOBase = open(path, "x+b")
283257
else:
@@ -295,101 +269,3 @@ async def get_range_async(
295269
return DBNStore.from_file(path)
296270
writer.seek(0) # rewind for read
297271
return DBNStore.from_bytes(writer.read())
298-
299-
def _pre_check_data_size(
300-
self,
301-
dataset: str,
302-
symbols: str,
303-
schema: Schema,
304-
start: str,
305-
end: Optional[str],
306-
stype_in: SType,
307-
limit: Optional[int],
308-
) -> None:
309-
if _is_size_limited(
310-
schema=schema,
311-
limit=limit,
312-
):
313-
return
314-
315-
if _is_period_limited(
316-
schema=schema,
317-
symbols=symbols,
318-
start=start,
319-
end=end,
320-
):
321-
return
322-
323-
metadata_api = MetadataHttpAPI(
324-
key=self._key,
325-
gateway=self._gateway,
326-
)
327-
request_size = metadata_api.get_billable_size(
328-
dataset=dataset,
329-
start=start,
330-
end=end,
331-
symbols=symbols,
332-
schema=schema,
333-
stype_in=stype_in,
334-
limit=limit,
335-
)
336-
337-
if request_size < WARN_REQUEST_SIZE:
338-
return
339-
340-
warnings.warn(
341-
message="""The size of this streaming request is greater than 5GB.
342-
It is recommended to submit a batch download request for large volumes
343-
of data, or break this request into smaller requests.
344-
This warning can be suppressed:
345-
https://docs.python.org/3/library/warnings.html""",
346-
category=BentoWarning,
347-
stacklevel=3, # This makes the error happen in user code
348-
)
349-
350-
351-
def _is_size_limited(
352-
schema: Schema,
353-
limit: Optional[int],
354-
max_size: int = WARN_REQUEST_SIZE,
355-
) -> bool:
356-
if limit is None:
357-
return False
358-
359-
estimated_size = limit * schema.get_record_type().size_hint()
360-
return estimated_size < max_size
361-
362-
363-
def _is_period_limited(
364-
schema: Schema,
365-
symbols: str,
366-
start: str,
367-
end: Optional[str],
368-
max_size: int = WARN_REQUEST_SIZE,
369-
) -> bool:
370-
if end is None:
371-
return False
372-
373-
if schema not in (
374-
Schema.OHLCV_1S,
375-
Schema.OHLCV_1M,
376-
Schema.OHLCV_1H,
377-
Schema.OHLCV_1D,
378-
Schema.DEFINITION,
379-
):
380-
return False
381-
382-
dt_start = pd.to_datetime(start, utc=True)
383-
dt_end = pd.to_datetime(end, utc=True)
384-
385-
# default scale to one day for ohlcv_1d and definition
386-
scale = {
387-
Schema.OHLCV_1S: 1,
388-
Schema.OHLCV_1M: 60,
389-
Schema.OHLCV_1H: 60 * 60,
390-
}.get(schema, 60 * 60 * 24)
391-
392-
num_symbols = len(symbols.split(","))
393-
num_records = num_symbols * (dt_end - dt_start).total_seconds() // scale
394-
estimated_size = num_records * schema.get_record_type().size_hint()
395-
return estimated_size < max_size

tests/test_common_enums.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -145,35 +145,3 @@ def test_int_flags_stringy_mixin(enum_type: Type[Flag]) -> None:
145145
assert str(record_flags) == ", ".join(
146146
f.name.lower() for f in enum_type if f in record_flags
147147
)
148-
149-
150-
def test_stype_deprecation() -> None:
151-
"""
152-
Test that a deprecation warning is emitted when
153-
accessing a deprecated SType member.
154-
"""
155-
with pytest.deprecated_call():
156-
SType.PRODUCT_ID
157-
158-
with pytest.deprecated_call():
159-
SType.NATIVE
160-
161-
with pytest.deprecated_call():
162-
SType.SMART
163-
164-
165-
@pytest.mark.parametrize(
166-
"name",
167-
[
168-
"product_id",
169-
"native",
170-
"smart",
171-
],
172-
)
173-
def test_stype_deprecation_strings(name: str) -> None:
174-
"""
175-
Test that a deprecation warning is emitted when
176-
constructing an SType from strings.
177-
"""
178-
with pytest.deprecated_call():
179-
SType(name)

0 commit comments

Comments
 (0)