Skip to content

Commit f7ee053

Browse files
committed
fix non geopandas flattening
1 parent c17a07f commit f7ee053

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

dataretrieval/waterdata/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,8 @@ def _handle_stats_nesting(
848848
# If geopandas not installed, return a pandas dataframe
849849
# otherwise return a geodataframe
850850
if not geopd:
851-
df = pd.json_normalize(body['features'])
851+
df = pd.json_normalize(body['features']).drop(columns=['type', 'properties.data'])
852+
df.columns = df.columns.str.split('.').str[-1]
852853
else:
853854
df = gpd.GeoDataFrame.from_features(body["features"]).drop(columns=['data'])
854855

@@ -862,7 +863,7 @@ def _handle_stats_nesting(
862863
["features", "properties", "data", "parameter_code"],
863864
["features", "properties", "data", "unit_of_measure"],
864865
["features", "properties", "data", "parent_time_series_id"],
865-
["features", "geometry", "coordinates"],
866+
#["features", "geometry", "coordinates"],
866867
],
867868
meta_prefix="",
868869
errors="ignore",
@@ -946,7 +947,7 @@ def get_stats_data(
946947
headers=headers,
947948
)
948949
body = resp.json()
949-
df1 = _handle_stats_nesting(body, geopd=GEOPANDAS)
950+
df1 = _handle_stats_nesting(body, geopd=False)
950951
dfs = pd.concat([dfs, df1], ignore_index=True)
951952
next_token = body['next']
952953
except Exception:

0 commit comments

Comments
 (0)