Skip to content

Commit fb63ec7

Browse files
committed
Add is_available() to runtime modules
1 parent 5c2b112 commit fb63ec7

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

monic/runtime/datetime.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
# Copyright (c) 2024-2025 Cognica, Inc.
55
#
66

7-
from monic.expressions.registry import monic_bind_default_module
7+
from monic.expressions.registry import (
8+
monic_bind_default,
9+
monic_bind_default_module,
10+
)
811

912

1013
monic_bind_default_module("datetime", "datetime")
14+
15+
16+
@monic_bind_default("datetime.is_available")
17+
def datetime_is_available() -> bool:
18+
return True

monic/runtime/json.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ def json_dumps(obj, *args, **kwargs) -> str:
1818
@monic_bind_default("json.loads")
1919
def json_loads(s, *args, **kwargs) -> t.Any:
2020
return json.loads(s, *args, **kwargs)
21+
22+
23+
@monic_bind_default("json.is_available")
24+
def json_is_available() -> bool:
25+
return True

monic/runtime/numpy.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@
44
# Copyright (c) 2024-2025 Cognica, Inc.
55
#
66

7-
from monic.expressions.registry import monic_bind_default_module
7+
from monic.expressions.registry import (
8+
monic_bind_default,
9+
monic_bind_default_module,
10+
)
811

912

1013
try:
1114
monic_bind_default_module("numpy", "np")
15+
_has_numpy = True # pragma: no cover
1216
except ImportError: # pragma: no cover
13-
pass # pragma: no cover
17+
_has_numpy = False # pragma: no cover
18+
19+
20+
@monic_bind_default("np.is_available")
21+
def np_is_available() -> bool:
22+
return _has_numpy

monic/runtime/pandas.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@
44
# Copyright (c) 2024-2025 Cognica, Inc.
55
#
66

7-
from monic.expressions.registry import monic_bind_default_module
7+
from monic.expressions.registry import (
8+
monic_bind_default,
9+
monic_bind_default_module,
10+
)
811

912

1013
try:
1114
monic_bind_default_module("pandas", "pd")
15+
_has_pandas = True # pragma: no cover
1216
except ImportError: # pragma: no cover
13-
pass # pragma: no cover
17+
_has_pandas = False # pragma: no cover
18+
19+
20+
@monic_bind_default("pd.is_available")
21+
def pd_is_available() -> bool:
22+
return _has_pandas

monic/runtime/polars.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@
44
# Copyright (c) 2024-2025 Cognica, Inc.
55
#
66

7-
from monic.expressions.registry import monic_bind_default_module
7+
from monic.expressions.registry import (
8+
monic_bind_default,
9+
monic_bind_default_module,
10+
)
811

912

1013
try:
1114
monic_bind_default_module("polars", "pl")
15+
_has_polars = True # pragma: no cover
1216
except ImportError: # pragma: no cover
13-
pass # pragma: no cover
17+
_has_polars = False # pragma: no cover
18+
19+
20+
@monic_bind_default("pl.is_available")
21+
def pl_is_available() -> bool:
22+
return _has_polars

monic/runtime/time.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ def time_time() -> float:
1717
@monic_bind_default("time.monotonic")
1818
def time_monotonic() -> float:
1919
return time.monotonic()
20+
21+
22+
@monic_bind_default("time.is_available")
23+
def time_is_available() -> bool:
24+
return True

0 commit comments

Comments
 (0)