Skip to content

Commit

Permalink
fix geopandas error
Browse files Browse the repository at this point in the history
  • Loading branch information
corentincarton committed Dec 11, 2024
1 parent f96f841 commit 25ad8d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
19 changes: 0 additions & 19 deletions hat/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,6 @@ def is_csv(file_path):
return file_extension.lower() == ".csv"


def read_csv_and_cache(fpath: str) -> gpd.GeoDataFrame:
"""read .csv file and cache to pickle"""

# cache filepath
cache_fname = os.path.splitext(os.path.basename(fpath))[0]
cache_fpath = get_tmp_filepath(cache_fname, extension=".pickle")

# use cache if it exists
if os.path.exists(cache_fpath):
gdf = pd.read_pickle(cache_fpath)

# otherwise load from user defined filepath (and then cache)
else:
gdf = gpd.read_file(fpath)
gdf.to_pickle(cache_fpath)

return gdf


""" other data (e.g. non geospatial)"""


Expand Down
6 changes: 3 additions & 3 deletions hat/observations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import geopandas as gpd
import pandas as pd

from hat.data import is_csv, read_csv_and_cache
from hat.data import is_csv
from hat.filters import filter_dataframe


Expand All @@ -28,7 +28,7 @@ def add_geometry_column(gdf: gpd.GeoDataFrame, coord_names):
# Create a geometry column
gdf["geometry"] = gpd.points_from_xy(gdf[x_coord_name], gdf[y_coord_name])

return gdf
return gpd.GeoDataFrame(gdf, geometry="geometry")


def read_station_metadata_file(
Expand All @@ -39,7 +39,7 @@ def read_station_metadata_file(

try:
if is_csv(fpath):
gdf = read_csv_and_cache(fpath)
gdf = gpd.read_file(fpath)
gdf = add_geometry_column(gdf, coord_names)
gdf = gdf.set_crs(epsg=epsg)
else:
Expand Down

0 comments on commit 25ad8d6

Please sign in to comment.