Skip to content

Commit

Permalink
Replaced .ix attribute
Browse files Browse the repository at this point in the history
This has been removed in pandas 1.0.0 (see
pandas-dev/pandas#26438)
  • Loading branch information
Chilipp committed Mar 16, 2020
1 parent 8a7f71a commit 010b1d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions gwgen/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def get(name):
ccday[['mean_cloud', 'wind']], left_index=True,
right_index=True, how='left')
except TypeError: # indices to not match
reference = cday.ix[1:0] # create empty data frame
reference = cday.iloc[1:0] # create empty data frame
reference['mean_cloud'] = np.array([],
dtype=ccday.mean_cloud.dtype)
reference['wind'] = np.array([],
Expand All @@ -269,10 +269,10 @@ def get(name):
ccmonth[['mean_cloud', 'wind']], left_index=True,
right_index=True, how='left')
# set cloud and wind to 0 where we have no reference
exp_input.ix[exp_input.mean_cloud.isnull(),
['mean_cloud', 'wind']] = 0
exp_input.loc[exp_input.mean_cloud.isnull(),
['mean_cloud', 'wind']] = 0
except TypeError: # indices do not match
exp_input = cmonth.ix[1:0] # create empty data frame
exp_input = cmonth.iloc[1:0] # create empty data frame
exp_input['mean_cloud'] = np.array([],
dtype=ccmonth.mean_cloud.dtype)
exp_input['wind'] = np.array([],
Expand Down Expand Up @@ -515,15 +515,15 @@ def setup_from_scratch(self):
# mask out non-complete months for cloud validation and months with
# 0 or 1 cloud fraction
if 'mean_cloud' in names:
df.ix[df['mean_cloud_ref'].isnull().values |
(df['mean_cloud'] == 0.0) |
(df['mean_cloud'] == 1.0),
['mean_cloud_sim', 'mean_cloud_ref']] = np.nan
df.loc[df['mean_cloud_ref'].isnull().values |
(df['mean_cloud'] == 0.0) |
(df['mean_cloud'] == 1.0),
['mean_cloud_sim', 'mean_cloud_ref']] = np.nan
# mask out non-complete wind for wind validation and months with
# a mean wind speed of 0
if 'wind' in names:
df.ix[df['wind_ref'].isnull().values | (df['wind'] == 0.0),
['wind_sim', 'wind_ref']] = np.nan
df.loc[df['wind_ref'].isnull().values | (df['wind'] == 0.0),
['wind_sim', 'wind_ref']] = np.nan
df.drop(['mean_cloud', 'wind'], 1, inplace=True)
df.set_index('day', append=True, inplace=True)

Expand Down Expand Up @@ -698,7 +698,7 @@ def calc(v1, v2, name):

def significance_fractions(self, series):
"The percentage of stations with no significant difference"
return 100. - (len(series.ix[series.notnull() & (series)]) /
return 100. - (len(series.loc[series.notnull() & (series)]) /
series.count())*100.

def run(self, info):
Expand Down Expand Up @@ -745,7 +745,7 @@ def plot_map(self):
g.agg(dict(zip(names, repeat('sum')))), left_index=True,
right_index=True, suffixes=['', '_sum'])
df_lola = EvaluationPreparation.from_task(self).station_list
df_lola = df_lola.ix[~df_lola.duplicated('id').values]
df_lola = df_lola.loc[~df_lola.duplicated('id').values]
df_lola.set_index('id', inplace=True)
df_plot = df_lola.merge(df_fract, how='right', left_index=True,
right_index=True)
Expand Down
10 changes: 5 additions & 5 deletions gwgen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,11 @@ def select(self, grid=None, grid_output=None, stations_output=None,
df_centers.set_index(['clon', 'clat'], inplace=True)
df_stations.set_index(['clon', 'clat'], inplace=True)
merged = df_centers.merge(
df_stations.ix[indices_closest][['id']].rename(
df_stations.loc[indices_closest][['id']].rename(
columns={'id': 'nearest_station'}),
left_index=True, right_index=True, how='outer')
merged = merged.merge(
df_stations.ix[indices_longest][['id']].rename(
df_stations.loc[indices_longest][['id']].rename(
columns={'id': 'longest_record'}),
left_index=True, right_index=True, how='outer')

Expand Down Expand Up @@ -685,7 +685,7 @@ def create_test_sample(self, test_dir, stations, no_cloud=False,

def is_complete(s):
ndays = 366 if calendar.isleap(s.name[1]) else 365
s[:] = s.ix[~s.index.duplicated()].count() == ndays
s[:] = s.loc[~s.index.duplicated()].count() == ndays
return s

stations = self._get_stations(stations)
Expand Down Expand Up @@ -732,7 +732,7 @@ def is_complete(s):
df_bool[col] = df_bool[col].astype(bool)
g = df_bool.groupby(level=['station_id', 'year'])
mask = g.transform(is_complete).values.any(axis=1)
df = df.ix[mask]
df = df.loc[mask]

g = df.groupby(['station_id', 'year'],
as_index=False)
Expand All @@ -742,7 +742,7 @@ def is_complete(s):
self.logger.debug(
'Saving EECRA test sample with %i years from %i to '
'%s', n, tot, target)
df.ix[1:0].to_csv(target, index=False)
df.iloc[1:0].to_csv(target, index=False)
igrp = next(idx_groups)
for i, (key, group) in enumerate(g):
if i == igrp:
Expand Down
20 changes: 10 additions & 10 deletions gwgen/parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,17 +1781,17 @@ def calculate_monthly(df):
wet = df.wet_day.values.astype(bool)
return pd.DataFrame.from_dict(OrderedDict([
('wet_day', [df.wet_day.sum()]),
('mean_cloud_wet', [df.mean_cloud.ix[wet].mean()]),
('mean_cloud_dry', [df.mean_cloud.ix[~wet].mean()]),
('mean_cloud_wet', [df.mean_cloud.loc[wet].mean()]),
('mean_cloud_dry', [df.mean_cloud.loc[~wet].mean()]),
('mean_cloud', [df.mean_cloud.mean()]),
('sd_cloud_wet', [df.mean_cloud.ix[wet].std()]),
('sd_cloud_dry', [df.mean_cloud.ix[~wet].std()]),
('sd_cloud_wet', [df.mean_cloud.loc[wet].std()]),
('sd_cloud_dry', [df.mean_cloud.loc[~wet].std()]),
('sd_cloud', [df.mean_cloud.std()]),
('wind_wet', [df.wind.ix[wet].mean()]),
('wind_dry', [df.wind.ix[~wet].mean()]),
('wind_wet', [df.wind.loc[wet].mean()]),
('wind_dry', [df.wind.loc[~wet].mean()]),
('wind', [df.wind.mean()]),
('sd_wind_wet', [df.wind.ix[wet].std()]),
('sd_wind_dry', [df.wind.ix[~wet].std()]),
('sd_wind_wet', [df.wind.loc[wet].std()]),
('sd_wind_dry', [df.wind.loc[~wet].std()]),
('sd_wind', [df.wind.std()]),
]))
else:
Expand Down Expand Up @@ -1927,7 +1927,7 @@ def year_complete(series):
suffixes=['', '_year']).set_index(names)

ycomplete_cols = [col + '_complete_year' for col in cols]
self.data = all_monthly.ix[
self.data = all_monthly.loc[
all_monthly[ycomplete_cols].values.all(axis=1)]


Expand Down Expand Up @@ -2373,7 +2373,7 @@ def year_complete(series):
suffixes=['', '_year']).set_index(names)

ycomplete_cols = [col + '_complete_year' for col in cols]
monthly = all_monthly.ix[
monthly = all_monthly.loc[
all_monthly[ycomplete_cols].values.all(axis=1)][[]].reset_index()
self.data = self.cdaily_cloud.data.reset_index().merge(
monthly, how='inner', on=['id', 'year', 'month'],
Expand Down
2 changes: 1 addition & 1 deletion gwgen/preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def create_geog(table):
# download inventory
t.download_src()
ghcn = t.station_list
ghcn = ghcn.ix[ghcn.vname == 'PRCP'].set_index('id')
ghcn = ghcn.loc[ghcn.vname == 'PRCP'].set_index('id')
ghcn.to_sql('ghcn_inventory', self.engine, if_exists='replace')
create_geog('ghcn_inventory')

Expand Down

0 comments on commit 010b1d9

Please sign in to comment.