Skip to content

Commit 010b1d9

Browse files
committed
Replaced .ix attribute
This has been removed in pandas 1.0.0 (see pandas-dev/pandas#26438)
1 parent 8a7f71a commit 010b1d9

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

gwgen/evaluation.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def get(name):
253253
ccday[['mean_cloud', 'wind']], left_index=True,
254254
right_index=True, how='left')
255255
except TypeError: # indices to not match
256-
reference = cday.ix[1:0] # create empty data frame
256+
reference = cday.iloc[1:0] # create empty data frame
257257
reference['mean_cloud'] = np.array([],
258258
dtype=ccday.mean_cloud.dtype)
259259
reference['wind'] = np.array([],
@@ -269,10 +269,10 @@ def get(name):
269269
ccmonth[['mean_cloud', 'wind']], left_index=True,
270270
right_index=True, how='left')
271271
# set cloud and wind to 0 where we have no reference
272-
exp_input.ix[exp_input.mean_cloud.isnull(),
273-
['mean_cloud', 'wind']] = 0
272+
exp_input.loc[exp_input.mean_cloud.isnull(),
273+
['mean_cloud', 'wind']] = 0
274274
except TypeError: # indices do not match
275-
exp_input = cmonth.ix[1:0] # create empty data frame
275+
exp_input = cmonth.iloc[1:0] # create empty data frame
276276
exp_input['mean_cloud'] = np.array([],
277277
dtype=ccmonth.mean_cloud.dtype)
278278
exp_input['wind'] = np.array([],
@@ -515,15 +515,15 @@ def setup_from_scratch(self):
515515
# mask out non-complete months for cloud validation and months with
516516
# 0 or 1 cloud fraction
517517
if 'mean_cloud' in names:
518-
df.ix[df['mean_cloud_ref'].isnull().values |
519-
(df['mean_cloud'] == 0.0) |
520-
(df['mean_cloud'] == 1.0),
521-
['mean_cloud_sim', 'mean_cloud_ref']] = np.nan
518+
df.loc[df['mean_cloud_ref'].isnull().values |
519+
(df['mean_cloud'] == 0.0) |
520+
(df['mean_cloud'] == 1.0),
521+
['mean_cloud_sim', 'mean_cloud_ref']] = np.nan
522522
# mask out non-complete wind for wind validation and months with
523523
# a mean wind speed of 0
524524
if 'wind' in names:
525-
df.ix[df['wind_ref'].isnull().values | (df['wind'] == 0.0),
526-
['wind_sim', 'wind_ref']] = np.nan
525+
df.loc[df['wind_ref'].isnull().values | (df['wind'] == 0.0),
526+
['wind_sim', 'wind_ref']] = np.nan
527527
df.drop(['mean_cloud', 'wind'], 1, inplace=True)
528528
df.set_index('day', append=True, inplace=True)
529529

@@ -698,7 +698,7 @@ def calc(v1, v2, name):
698698

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

704704
def run(self, info):
@@ -745,7 +745,7 @@ def plot_map(self):
745745
g.agg(dict(zip(names, repeat('sum')))), left_index=True,
746746
right_index=True, suffixes=['', '_sum'])
747747
df_lola = EvaluationPreparation.from_task(self).station_list
748-
df_lola = df_lola.ix[~df_lola.duplicated('id').values]
748+
df_lola = df_lola.loc[~df_lola.duplicated('id').values]
749749
df_lola.set_index('id', inplace=True)
750750
df_plot = df_lola.merge(df_fract, how='right', left_index=True,
751751
right_index=True)

gwgen/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,11 @@ def select(self, grid=None, grid_output=None, stations_output=None,
466466
df_centers.set_index(['clon', 'clat'], inplace=True)
467467
df_stations.set_index(['clon', 'clat'], inplace=True)
468468
merged = df_centers.merge(
469-
df_stations.ix[indices_closest][['id']].rename(
469+
df_stations.loc[indices_closest][['id']].rename(
470470
columns={'id': 'nearest_station'}),
471471
left_index=True, right_index=True, how='outer')
472472
merged = merged.merge(
473-
df_stations.ix[indices_longest][['id']].rename(
473+
df_stations.loc[indices_longest][['id']].rename(
474474
columns={'id': 'longest_record'}),
475475
left_index=True, right_index=True, how='outer')
476476

@@ -685,7 +685,7 @@ def create_test_sample(self, test_dir, stations, no_cloud=False,
685685

686686
def is_complete(s):
687687
ndays = 366 if calendar.isleap(s.name[1]) else 365
688-
s[:] = s.ix[~s.index.duplicated()].count() == ndays
688+
s[:] = s.loc[~s.index.duplicated()].count() == ndays
689689
return s
690690

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

737737
g = df.groupby(['station_id', 'year'],
738738
as_index=False)
@@ -742,7 +742,7 @@ def is_complete(s):
742742
self.logger.debug(
743743
'Saving EECRA test sample with %i years from %i to '
744744
'%s', n, tot, target)
745-
df.ix[1:0].to_csv(target, index=False)
745+
df.iloc[1:0].to_csv(target, index=False)
746746
igrp = next(idx_groups)
747747
for i, (key, group) in enumerate(g):
748748
if i == igrp:

gwgen/parameterization.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,17 +1781,17 @@ def calculate_monthly(df):
17811781
wet = df.wet_day.values.astype(bool)
17821782
return pd.DataFrame.from_dict(OrderedDict([
17831783
('wet_day', [df.wet_day.sum()]),
1784-
('mean_cloud_wet', [df.mean_cloud.ix[wet].mean()]),
1785-
('mean_cloud_dry', [df.mean_cloud.ix[~wet].mean()]),
1784+
('mean_cloud_wet', [df.mean_cloud.loc[wet].mean()]),
1785+
('mean_cloud_dry', [df.mean_cloud.loc[~wet].mean()]),
17861786
('mean_cloud', [df.mean_cloud.mean()]),
1787-
('sd_cloud_wet', [df.mean_cloud.ix[wet].std()]),
1788-
('sd_cloud_dry', [df.mean_cloud.ix[~wet].std()]),
1787+
('sd_cloud_wet', [df.mean_cloud.loc[wet].std()]),
1788+
('sd_cloud_dry', [df.mean_cloud.loc[~wet].std()]),
17891789
('sd_cloud', [df.mean_cloud.std()]),
1790-
('wind_wet', [df.wind.ix[wet].mean()]),
1791-
('wind_dry', [df.wind.ix[~wet].mean()]),
1790+
('wind_wet', [df.wind.loc[wet].mean()]),
1791+
('wind_dry', [df.wind.loc[~wet].mean()]),
17921792
('wind', [df.wind.mean()]),
1793-
('sd_wind_wet', [df.wind.ix[wet].std()]),
1794-
('sd_wind_dry', [df.wind.ix[~wet].std()]),
1793+
('sd_wind_wet', [df.wind.loc[wet].std()]),
1794+
('sd_wind_dry', [df.wind.loc[~wet].std()]),
17951795
('sd_wind', [df.wind.std()]),
17961796
]))
17971797
else:
@@ -1927,7 +1927,7 @@ def year_complete(series):
19271927
suffixes=['', '_year']).set_index(names)
19281928

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

19331933

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

23752375
ycomplete_cols = [col + '_complete_year' for col in cols]
2376-
monthly = all_monthly.ix[
2376+
monthly = all_monthly.loc[
23772377
all_monthly[ycomplete_cols].values.all(axis=1)][[]].reset_index()
23782378
self.data = self.cdaily_cloud.data.reset_index().merge(
23792379
monthly, how='inner', on=['id', 'year', 'month'],

gwgen/preproc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def create_geog(table):
249249
# download inventory
250250
t.download_src()
251251
ghcn = t.station_list
252-
ghcn = ghcn.ix[ghcn.vname == 'PRCP'].set_index('id')
252+
ghcn = ghcn.loc[ghcn.vname == 'PRCP'].set_index('id')
253253
ghcn.to_sql('ghcn_inventory', self.engine, if_exists='replace')
254254
create_geog('ghcn_inventory')
255255

0 commit comments

Comments
 (0)