Skip to content

Commit

Permalink
fix: fixes iobis#171
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushanand18 authored Dec 14, 2024
1 parent ba9819c commit e68f183
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pyobis/occurrences/occurrences.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def execute(self, **kwargs):
)
outdf = pd.concat(
[
outdf.infer_objects(),
outdf if len(outdf) else None,
pd.DataFrame(res["results"]).infer_objects(),
],
ignore_index=True,
Expand All @@ -159,7 +159,10 @@ def execute(self, **kwargs):
**kwargs,
)
outdf = pd.concat(
[outdf.infer_objects(), pd.DataFrame(res["results"]).infer_objects()],
[
outdf if len(outdf) else None,
pd.DataFrame(res["results"]).infer_objects(),
],
ignore_index=True,
)
logger.info(f"Fetched {size} records.")
Expand All @@ -176,16 +179,31 @@ def execute(self, **kwargs):
on="id",
how="inner",
)
self.data = merged
return self.data
self.data = outdf
self.data = {"total": len(merged), "results": merged}
# set the data as [total, results] K-V pair
# but still return the DataFrame since changing this
# will impact existing usage, and be a breaking change
return self.data["results"]
self.data = {"total": len(outdf), "results": outdf}

# again for not MeasurementOrFacts results, (simple search queries)
# should also return the DataFrame directly for backward compatibility
return self.data["results"]

return self.data

def to_pandas(self):
"""
Convert the results into a pandas DataFrame
"""
# if the data format of the query executed cannot be converted to a
# pandas.DataFrame which is true for other formats like .mvt or kml (not geojson)
# then we should be raising a not implemented rather relying around exceptions
# from pandas while converting
if self.__isKML:
raise NotImplementedError(
"to_pandas method is not yet available for these query types.",
)
return pd.DataFrame(self.data["results"])


Expand Down Expand Up @@ -400,7 +418,7 @@ def grid(
from pyobis import occurrences
occurrences.grid(100, True) // returns in GeoJSON format
ococcurrences.grid(1000, False) // returns in KML format
occurrences.grid(1000, False) // returns in KML format
"""
url = obis_baseurl + "occurrence/grid/" + str(precision)
scientificname = handle_arrstr(scientificname)
Expand Down

0 comments on commit e68f183

Please sign in to comment.