Skip to content

Commit

Permalink
Fix an unnecessary pandas import
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jul 21, 2022
1 parent c938c0f commit b6d784c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pyinaturalist_convert/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ def _to_models(value: InputTypes, model: Type[BaseModel] = Observation) -> Itera

def to_dicts(value: InputTypes) -> Iterable[Dict]:
"""Convert any supported input type into a observation (or other record type) dicts"""
from pandas import DataFrame

if not value:
return []
if isinstance(value, DataFrame):
if _is_dataframe(value):
return _df_to_dicts(value)
if isinstance(value, Dataset):
return value.dict
Expand Down Expand Up @@ -352,3 +350,12 @@ def _fix_dimensions(flat_observations):
for field in headers:
obs.setdefault(field, None)
return sorted(headers), flat_observations


def _is_dataframe(obj) -> bool:
try:
from pandas import DataFrame

return isinstance(obj, DataFrame)
except ImportError:
return False

0 comments on commit b6d784c

Please sign in to comment.