Skip to content

Commit 3d1def2

Browse files
committed
DEL: Deprecate mode param in get_cost
1 parent 0ffaf07 commit 3d1def2

File tree

5 files changed

+20
-33
lines changed

5 files changed

+20
-33
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 0.65.0 - TBD
44

5+
#### Deprecations
6+
- Deprecated `mode` parameter in `metadata.get_cost`, which will be removed in a future release
7+
58
#### Enhancements
69
- Added export of `CBBOMsg` and `BBOMsg` from `databento_dbn` to the root `databento` package
710

databento/common/parsing.py

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

3-
import warnings
43
from collections.abc import Iterable
54
from datetime import date
65
from datetime import datetime
@@ -277,13 +276,13 @@ def datetime_to_string(value: pd.Timestamp | datetime | date | str | int) -> str
277276
return pd.to_datetime(value).isoformat()
278277

279278

280-
def date_to_string(value: pd.Timestamp | date | str | int) -> str:
279+
def date_to_string(value: date | str) -> str:
281280
"""
282281
Return a valid date string from the given value.
283282
284283
Parameters
285284
----------
286-
value : pd.Timestamp, date, str, or int
285+
value : date or str
287286
The value to parse.
288287
289288
Returns
@@ -293,32 +292,10 @@ def date_to_string(value: pd.Timestamp | date | str | int) -> str:
293292
"""
294293
if isinstance(value, str):
295294
return value
296-
elif isinstance(value, date):
295+
elif type(value) is date:
297296
return value.isoformat()
298-
elif isinstance(value, int):
299-
warnings.warn(
300-
"Passing an int to `start_date` or `end_date` is deprecated and will be removed in v0.59.0."
301-
"Use a date or str instead.",
302-
DeprecationWarning,
303-
stacklevel=2,
304-
)
305-
return str(value)
306-
elif isinstance(value, pd.Timestamp):
307-
warnings.warn(
308-
"Passing a pandas Timestamp to `start_date` or `end_date` is deprecated and will be removed in v0.59.0."
309-
"Use a date or str instead.",
310-
DeprecationWarning,
311-
stacklevel=2,
312-
)
313-
return pd.to_datetime(value).date().isoformat()
314297
else:
315-
warnings.warn(
316-
f"Passing a {type(value)} to `start_date` or `end_date` is deprecated and will be removed in v0.59.0."
317-
"Use a date or str instead.",
318-
DeprecationWarning,
319-
stacklevel=2,
320-
)
321-
return pd.to_datetime(value).date().isoformat()
298+
raise TypeError(f"`{type(value)} is not supported. Only `date` and `str` are supported.")
322299

323300

324301
def optional_datetime_to_string(

databento/historical/api/metadata.py

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

3+
import warnings
34
from collections.abc import Iterable
45
from datetime import date
56
from datetime import datetime
@@ -19,6 +20,7 @@
1920
from databento.common.parsing import optional_datetime_to_string
2021
from databento.common.parsing import optional_symbols_list_to_list
2122
from databento.common.publishers import Dataset
23+
from databento.common.types import Default
2224
from databento.common.validation import validate_enum
2325
from databento.common.validation import validate_semantic_string
2426

@@ -399,7 +401,7 @@ def get_cost(
399401
dataset: Dataset | str,
400402
start: pd.Timestamp | datetime | date | str | int,
401403
end: pd.Timestamp | datetime | date | str | int | None = None,
402-
mode: FeedMode | str = "historical-streaming",
404+
mode: FeedMode | str | Default[None] = Default[None](None),
403405
symbols: Iterable[str | int] | str | int | None = None,
404406
schema: Schema | str = "trades",
405407
stype_in: SType | str = "raw_symbol",
@@ -425,8 +427,8 @@ def get_cost(
425427
Assumes UTC as timezone unless otherwise specified.
426428
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
427429
Defaults to the forward filled value of `start` based on the resolution provided.
428-
mode : FeedMode or str {'live', 'historical-streaming', 'historical'}, default 'historical-streaming'
429-
The data feed mode for the request.
430+
mode : FeedMode or str {'live', 'historical-streaming', 'historical'}, default `None`
431+
The data feed mode for the request. This parameter has been deprecated.
430432
symbols : Iterable[str | int] or str or int, optional
431433
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
432434
If 'ALL_SYMBOLS' or `None` then will select **all** symbols.
@@ -443,6 +445,13 @@ def get_cost(
443445
The cost in US dollars.
444446
445447
"""
448+
if not isinstance(mode, Default):
449+
warnings.warn(
450+
"The `mode` parameter is deprecated and will be removed in a future release.",
451+
DeprecationWarning,
452+
stacklevel=2,
453+
)
454+
446455
stype_in_valid = validate_enum(stype_in, SType, "stype_in")
447456
symbols_list = optional_symbols_list_to_list(symbols, stype_in_valid)
448457
data: dict[str, str | None] = {
@@ -453,7 +462,6 @@ def get_cost(
453462
"schema": str(validate_enum(schema, Schema, "schema")),
454463
"stype_in": str(stype_in_valid),
455464
"stype_out": str(SType.INSTRUMENT_ID),
456-
"mode": validate_enum(mode, FeedMode, "mode"),
457465
}
458466

459467
if limit is not None:

tests/test_historical_bento.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def test_to_df_with_pretty_ts_converts_timestamps_as_expected(
561561

562562
# Assert
563563
index0 = df.index[0]
564-
event0 = df["ts_event"][0]
564+
event0 = df["ts_event"].iloc[0]
565565
assert isinstance(index0, pd.Timestamp)
566566
assert isinstance(event0, pd.Timestamp)
567567
assert index0 == pd.Timestamp("2020-12-28 00:00:00.000000000+0000", tz="UTC")

tests/test_historical_metadata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ def test_get_cost_sends_expected_request(
292292
"schema": "mbo",
293293
"stype_in": "raw_symbol",
294294
"stype_out": "instrument_id",
295-
"mode": "historical-streaming",
296295
"limit": "1000000",
297296
}
298297
assert call["timeout"] == (100, 100)

0 commit comments

Comments
 (0)