Skip to content

Commit 12a4781

Browse files
committed
MOD: Standardize optional default arguments
1 parent a633421 commit 12a4781

18 files changed

+192
-40
lines changed

databento/common/bento.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,44 +592,76 @@ def to_file(self, path: Union[Path, str]) -> "FileBento":
592592

593593
return bento
594594

595-
def to_csv(self, path: Union[Path, str]) -> None:
595+
def to_csv(
596+
self,
597+
path: Union[Path, str],
598+
pretty_ts: bool = True,
599+
pretty_px: bool = True,
600+
map_symbols: bool = True,
601+
) -> None:
596602
"""
597603
Write the data to a file in CSV format.
598604
599605
Parameters
600606
----------
601607
path : Path or str
602608
The file path to write to.
609+
pretty_ts : bool, default True
610+
If all timestamp columns should be converted from UNIX nanosecond
611+
`int` to `pd.Timestamp` tz-aware (UTC).
612+
pretty_px : bool, default True
613+
If all price columns should be converted from `int` to `float` at
614+
the correct scale (using the fixed precision scalar 1e-9).
615+
map_symbols : bool, default True
616+
If symbology mappings from the metadata should be used to create
617+
a 'symbol' column, mapping the product ID to its native symbol for
618+
every record.
603619
604620
Notes
605621
-----
606622
Requires all the data to be brought up into memory to then be written.
607623
608624
"""
609625
self.to_df(
610-
pretty_ts=False,
611-
pretty_px=False,
612-
map_symbols=False,
626+
pretty_ts=pretty_ts,
627+
pretty_px=pretty_px,
628+
map_symbols=map_symbols,
613629
).to_csv(path)
614630

615-
def to_json(self, path: Union[Path, str]) -> None:
631+
def to_json(
632+
self,
633+
path: Union[Path, str],
634+
pretty_ts: bool = True,
635+
pretty_px: bool = True,
636+
map_symbols: bool = True,
637+
) -> None:
616638
"""
617639
Write the data to a file in JSON format.
618640
619641
Parameters
620642
----------
621643
path : Path or str
622644
The file path to write to.
645+
pretty_ts : bool, default True
646+
If all timestamp columns should be converted from UNIX nanosecond
647+
`int` to `pd.Timestamp` tz-aware (UTC).
648+
pretty_px : bool, default True
649+
If all price columns should be converted from `int` to `float` at
650+
the correct scale (using the fixed precision scalar 1e-9).
651+
map_symbols : bool, default True
652+
If symbology mappings from the metadata should be used to create
653+
a 'symbol' column, mapping the product ID to its native symbol for
654+
every record.
623655
624656
Notes
625657
-----
626658
Requires all the data to be brought up into memory to then be written.
627659
628660
"""
629661
self.to_df(
630-
pretty_ts=False,
631-
pretty_px=False,
632-
map_symbols=False,
662+
pretty_ts=pretty_ts,
663+
pretty_px=pretty_px,
664+
map_symbols=map_symbols,
633665
).to_json(path, orient="records", lines=True)
634666

635667
def request_symbology(self, client: "Historical") -> Dict[str, Any]:

examples/historical_batch_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
if __name__ == "__main__":
5-
db.log = "debug" # optional debug logging
5+
db.log = "debug" # Optional debug logging
66

77
key = "YOUR_API_KEY"
88
client = db.Historical(key=key)

examples/historical_batch_list_jobs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55

66
if __name__ == "__main__":
7-
db.log = "debug" # optional debug logging
7+
db.log = "debug" # Optional debug logging
88

99
key = "YOUR_API_KEY"
1010
client = db.Historical(key=key)
1111

1212
response = client.batch.list_jobs(
13-
states="received,queued,processing,done",
14-
since=None,
13+
states="received,queued,processing,done", # Included states
14+
since=None, # <-- Filter for jobs 'since' the given time
1515
)
1616

1717
pprint(response)

examples/historical_batch_submit_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
if __name__ == "__main__":
7-
db.log = "debug" # optional debug logging
7+
db.log = "debug" # Optional debug logging
88

99
key = "YOUR_API_KEY"
1010
client = db.Historical(key=key)
@@ -15,7 +15,7 @@
1515
schema="mbo",
1616
start="2022-06-10T12:00",
1717
end="2022-06-10T14:00",
18-
limit=1000, # <-- limiting batch request to 1000 records only
18+
limit=1000, # <-- Limiting batch request to 1000 records only
1919
encoding="csv",
2020
compression="zstd",
2121
delivery="download",

examples/historical_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
if __name__ == "__main__":
5-
db.log = "debug" # optional debug logging
5+
db.log = "debug" # Optional debug logging
66

77
key = "YOUR_API_KEY"
88
client = db.Historical(key=key)

examples/historical_metadata_get_billable_size.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
if __name__ == "__main__":
5-
db.log = "debug" # optional debug logging
5+
db.log = "debug" # Optional debug logging
66

77
key = "YOUR_API_KEY"
88
client = db.Historical(key=key)

examples/historical_metadata_get_cost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
if __name__ == "__main__":
5-
db.log = "debug" # optional debug logging
5+
db.log = "debug" # Optional debug logging
66

77
key = "YOUR_API_KEY"
88
client = db.Historical(key=key)

examples/historical_metadata_get_record_count.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
if __name__ == "__main__":
5-
db.log = "debug" # optional debug logging
5+
db.log = "debug" # Optional debug logging
66

77
key = "YOUR_API_KEY"
88
client = db.Historical(key=key)

examples/historical_metadata_list_unit_price.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
if __name__ == "__main__":
7-
db.log = "debug" # optional debug logging
7+
db.log = "debug" # Optional debug logging
88

99
key = "YOUR_API_KEY"
1010
client = db.Historical(key=key)

examples/historical_symbology_resolve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
if __name__ == "__main__":
8-
db.log = "debug" # optional debug logging
8+
db.log = "debug" # Optional debug logging
99

1010
key = "YOUR_API_KEY"
1111
client = db.Historical(key=key)

0 commit comments

Comments
 (0)