-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Expose tiledbsoma stats as JSON string or Python-parsed (#2958)
* [python] Expose tiledbsoma stats as JSON string or Python dict * code-review feedback
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2024 TileDB, Inc. | ||
# | ||
# Licensed under the MIT License. | ||
|
||
import json | ||
from typing import Dict, List, Literal, Union, cast | ||
|
||
from .pytiledbsoma import tiledbsoma_stats_string | ||
|
||
ParsedStats = List[Dict[Literal["counters", "timers"], Dict[str, Union[float, int]]]] | ||
|
||
|
||
def tiledbsoma_stats_json() -> str: | ||
"""Returns tiledbsoma stats as a JSON string""" | ||
# cast is needed for pybind11 things | ||
return cast(str, tiledbsoma_stats_string()) | ||
|
||
|
||
def tiledbsoma_stats_as_py() -> ParsedStats: | ||
"""Returns tiledbsoma stats as a Python dict""" | ||
# cast is needed for pybind11 things | ||
return cast(ParsedStats, json.loads(tiledbsoma_stats_string())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import tiledbsoma | ||
|
||
|
||
def test_stats_json(): | ||
out = tiledbsoma.tiledbsoma_stats_json() | ||
assert isinstance(out, str) | ||
assert out[0] == "[" | ||
assert out[-2] == "]" | ||
assert out[-1] == "\n" | ||
|
||
|
||
def test_stats_as_py(): | ||
out = tiledbsoma.tiledbsoma_stats_as_py() | ||
assert isinstance(out, list) |