◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
23 changes: 11 additions & 12 deletions src/scyjava/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import math
from bisect import insort
from pathlib import Path
from typing import Any, Callable, Dict, List, NamedTuple

Expand Up @@ -677,7 +678,7 @@ def _stock_py_converters() -> List:
priority=Priority.VERY_LOW,
),
]
if _import_pandas(required=False):
converters.append(
Converter(
name="org.scijava.table.Table -> pandas.DataFrame",
Expand Down Expand Up @@ -716,7 +717,7 @@ def _stock_py_converters() -> List:
),
]
)
if _import_numpy(required=False):
converters.append(
Converter(
name="primitive array -> numpy.ndarray",
Expand Down Expand Up @@ -803,16 +804,15 @@ def _jarray_shape(jarr):
return shape


def _import_numpy(required=True):
try:
import numpy as np

return np
except ImportError as e:
if required:
msg = "The NumPy library is missing (https://numpy.org/). "
msg += "Please install it before using this function."
raise RuntimeError(msg) from e


######################################
Expand All @@ -838,16 +838,15 @@ def _convert_table(obj: Any):
return None


def _import_pandas(required=True):
try:
import pandas as pd

return pd
except ImportError as e:
if required:
msg = "The Pandas library is missing (http://pandas.pydata.org/). "
msg += "Please install it before using this function."
raise RuntimeError(msg) from e


def _table_to_pandas(table):
Expand Down
Loading
Toggle all file notes Toggle all file annotations