Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Pandas 2.x #94

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions climada_petals/entity/exposures/openstreetmap/osm_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import urllib.request

import geopandas as gpd
import numpy as np
import pandas as pd
from osgeo import ogr, gdal
import overpy
import shapely
Expand Down Expand Up @@ -417,28 +417,29 @@ def retrieve_cis(self, ci_type):
"""
# features consisting in points and multipolygon results:
if ci_type in ['healthcare','education','food']:
gdf = self.retrieve('points', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query'])
gdf = gdf.append(
gdf = pd.concat([
self.retrieve('points', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query']),
self.retrieve('multipolygons', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query']))
DICT_CIS_OSM[ci_type]['osm_query']),
])

# features consisting in multipolygon results:
elif ci_type in ['air']:
gdf = self.retrieve('multipolygons', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query'])
DICT_CIS_OSM[ci_type]['osm_query'])

# features consisting in points, multipolygons and lines:
elif ci_type in ['gas','oil','telecom','water','wastewater','power',
'rail','road']:
gdf = self.retrieve('points', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query'])
gdf = gdf.append(
gdf = pd.concat([
self.retrieve('points', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query']),
self.retrieve('multipolygons', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query']))
gdf = gdf.append(
DICT_CIS_OSM[ci_type]['osm_query']),
self.retrieve('lines', DICT_CIS_OSM[ci_type]['osm_keys'],
DICT_CIS_OSM[ci_type]['osm_query']))
DICT_CIS_OSM[ci_type]['osm_query']),
])
else:
LOGGER.warning('feature not in DICT_CIS_OSM. Returning empty gdf')
gdf = gpd.GeoDataFrame()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def init_testdata():
@staticmethod
def assert_pd_frame_equal(df1, df2, **kwds):
"""Assert that two dataframes are equal, ignoring ordering of columns"""
from pandas.util.testing import assert_frame_equal
from pandas.testing import assert_frame_equal
return assert_frame_equal(df1.sort_index(axis=1), df2.sort_index(axis=1),
check_names=True, **kwds)

Expand Down
2 changes: 1 addition & 1 deletion climada_petals/hazard/emulator/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def seasonal_average(data, season):
data = data[(data['year'] > year_min) & (data['year'] <= year_max)]
data = data.reset_index(drop=True)
data = data.groupby('year').mean().reset_index()
return data.drop('month', 1)
return data.drop('month', axis=1)


def seasonal_statistics(events, season):
Expand Down
6 changes: 4 additions & 2 deletions climada_petals/hazard/low_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import datetime as dt
from pathlib import Path
import cftime
import xarray as xr
import geopandas as gpd
import numpy as np
import numba
import pandas as pd
import xarray as xr


from sklearn.cluster import DBSCAN
from sklearn.neighbors import BallTree
Expand Down Expand Up @@ -754,7 +756,7 @@ def data_preprocessing_percentile(percentile, yearrange, yearrange_ref,
dataf = _xarray_to_geopandas(data_chunk)
first_file = False
else:
dataf = dataf.append(_xarray_to_geopandas(data_chunk))
dataf = pd.concat([dataf, _xarray_to_geopandas(data_chunk)])
del data_chunk
dataf = dataf.sort_values(['lat', 'lon', 'dtime'], ascending=[True, True, True])
return dataf.reset_index(drop=True), centroids
Expand Down
2 changes: 1 addition & 1 deletion climada_petals/hazard/wildfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def _clean_firms_df(self, df_firms):
df_firms_viirs = df_firms_viirs.drop(df_firms_viirs[ \
df_firms_viirs.confidence == 'l'].index)
df_firms_viirs = df_firms_viirs.rename(columns={'bright_ti4':'brightness'})
temp = temp.append(df_firms_viirs, sort=True)
temp = pd.concat([temp, df_firms_viirs], sort=True)
temp = temp.drop(columns=['bright_ti4'])

df_firms = temp
Expand Down