Skip to content

Commit

Permalink
Use context manager to stop warnings not is_copy
Browse files Browse the repository at this point in the history
df.is_copy was deprecated.
  • Loading branch information
has2k1 committed Jan 13, 2018
1 parent b5fda5e commit 9b068b4
Show file tree
Hide file tree
Showing 17 changed files with 7 additions and 21 deletions.
1 change: 0 additions & 1 deletion plotnine/coords/coord.py
Expand Up @@ -204,7 +204,6 @@ def munch_data(data, dist):
len(data)-1])

munched = data.loc[idx, data.columns.difference(['x', 'y'])]
munched.is_copy = None
munched['x'] = x
munched['y'] = y
munched.reset_index(drop=True, inplace=True)
Expand Down
2 changes: 0 additions & 2 deletions plotnine/geoms/geom.py
Expand Up @@ -219,7 +219,6 @@ def draw_layer(self, data, layout, coord, **params):
for pid, pdata in data.groupby('PANEL'):
if len(pdata) == 0:
continue
pdata.is_copy = None
ploc = pid - 1
panel_params = layout.panel_params[ploc]
ax = layout.axs[ploc]
Expand Down Expand Up @@ -258,7 +257,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
"""
for _, gdata in data.groupby('group'):
gdata.reset_index(inplace=True, drop=True)
gdata.is_copy = None
self.draw_group(gdata, panel_params, coord, ax, **params)

@staticmethod
Expand Down
1 change: 0 additions & 1 deletion plotnine/geoms/geom_abline.py
Expand Up @@ -62,6 +62,5 @@ def draw_panel(self, data, panel_params, coord, ax, **params):

for _, gdata in data.groupby('group'):
gdata.reset_index(inplace=True)
gdata.is_copy = None
geom_segment.draw_group(gdata, panel_params,
coord, ax, **params)
1 change: 0 additions & 1 deletion plotnine/geoms/geom_dotplot.py
Expand Up @@ -92,7 +92,6 @@ def stackdots(a):
for j in range(int(c))]
data = data.iloc[idx]
data.reset_index(inplace=True, drop=True)
data.is_copy = None
# Next part will set the position of each dot within each stack
# If stackgroups=TRUE, split only on x (or y) and panel;
# if not stacking, also split by group
Expand Down
1 change: 0 additions & 1 deletion plotnine/geoms/geom_hline.py
Expand Up @@ -51,6 +51,5 @@ def draw_panel(self, data, panel_params, coord, ax, **params):

for _, gdata in data.groupby('group'):
gdata.reset_index(inplace=True)
gdata.is_copy = None
geom_segment.draw_group(gdata, panel_params,
coord, ax, **params)
2 changes: 0 additions & 2 deletions plotnine/geoms/geom_path.py
Expand Up @@ -89,7 +89,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
c = Counter(data['group'])
counts = np.array([c[v] for v in data['group']])
data = data[counts >= 2]
data.is_copy = None

if len(data) < 2:
return
Expand All @@ -108,7 +107,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
else:
for _, gdata in data.groupby('group'):
gdata.reset_index(inplace=True, drop=True)
gdata.is_copy = None
self.draw_group(gdata, panel_params, coord, ax, **params)

@staticmethod
Expand Down
1 change: 0 additions & 1 deletion plotnine/geoms/geom_point.py
Expand Up @@ -31,7 +31,6 @@ def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params)
units = 'shape'
for _, udata in groupby_with_null(data, units):
udata.is_copy = None
udata.reset_index(inplace=True, drop=True)
geom_point.draw_unit(udata, panel_params, coord,
ax, **params)
Expand Down
1 change: 0 additions & 1 deletion plotnine/geoms/geom_ribbon.py
Expand Up @@ -39,7 +39,6 @@ def draw_group(data, panel_params, coord, ax, **params):
raise PlotnineError(msg)

for _, udata in groupby_with_null(data, units):
udata.is_copy = None
udata.reset_index(inplace=True, drop=True)
geom_ribbon.draw_unit(udata, panel_params, coord,
ax, **params)
Expand Down
2 changes: 0 additions & 2 deletions plotnine/geoms/geom_violin.py
Expand Up @@ -53,8 +53,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
quantiles = params['draw_quantiles']

for _, df in data.groupby('group'):
df.is_copy = None

# Find the points for the line to go all the way around
df['xminv'] = (df['x'] - df['violinwidth'] *
(df['x'] - df['xmin']))
Expand Down
1 change: 0 additions & 1 deletion plotnine/geoms/geom_vline.py
Expand Up @@ -51,7 +51,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):

for _, gdata in data.groupby('group'):
gdata.reset_index(inplace=True)
gdata.is_copy = None
geom_segment.draw_group(gdata, panel_params,
coord, ax, **params)

Expand Down
7 changes: 7 additions & 0 deletions plotnine/ggplot.py
Expand Up @@ -181,6 +181,13 @@ def draw(self, return_ggplot=False):
This method does not modify the original ggplot object. You can
get the modified ggplot object with :py:`return_ggplot=True`.
"""
# Pandas deprecated is_copy, and when we create new dataframes
# from slices we do not want complaints. We always uses the
# new frames knowing that they are separate from the original.
with pd.option_context('mode.chained_assignment', None):
return self._draw(return_ggplot)

def _draw(self, return_ggplot=False):
# Prevent against any modifications to the users
# ggplot object. Do the copy here as we may/may not
# assign a default theme
Expand Down
1 change: 0 additions & 1 deletion plotnine/guides/guide_legend.py
Expand Up @@ -311,7 +311,6 @@ def draw(self):
# overlay geoms
for gl in self.glayers:
data = gl.data.iloc[i]
data.is_copy = None
da = gl.geom.draw_legend(data, da, gl.layer)
drawings.append(da)
themeable['legend_key'].append(drawings)
Expand Down
2 changes: 0 additions & 2 deletions plotnine/positions/position_stack.py
Expand Up @@ -70,8 +70,6 @@ def compute_panel(cls, data, scales, params):
negative = data['ymax'] < 0
neg = data.loc[negative]
pos = data.loc[~negative]
neg.is_copy = None
pos.is_copy = None

if len(neg):
neg = cls.collide(neg, params=params)
Expand Down
1 change: 0 additions & 1 deletion plotnine/stats/stat.py
Expand Up @@ -299,7 +299,6 @@ def compute_panel(cls, data, scales, **params):

stats = []
for _, old in data.groupby('group'):
old.is_copy = None
new = cls.compute_group(old, scales, **params)
unique = uniquecols(old)
missing = unique.columns.difference(new.columns)
Expand Down
1 change: 0 additions & 1 deletion plotnine/stats/stat_bindot.py
Expand Up @@ -198,7 +198,6 @@ def func(df):
if params['drop']:
data = data[data['count'] > 0]
data.reset_index(inplace=True, drop=True)
data.is_copy = None

if params['binaxis'] == 'x':
data['x'] = data.pop('bincenter')
Expand Down
1 change: 0 additions & 1 deletion plotnine/stats/stat_smooth.py
Expand Up @@ -142,7 +142,6 @@ def setup_data(self, data):
"""
data = data[np.isfinite(data['x']) &
np.isfinite(data['y'])]
data.is_copy = None
return data

def setup_params(self, data):
Expand Down
2 changes: 0 additions & 2 deletions plotnine/utils.py
Expand Up @@ -610,7 +610,6 @@ def groupby_apply(df, cols, func, *args, **kwargs):
for _, d in df.groupby(cols):
# function fn should be free to modify dataframe d, therefore
# do not mark d as a slice of df i.e no SettingWithCopyWarning
d.is_copy = None
lst.append(func(d, *args, **kwargs))
return pd.concat(lst, axis=axis, ignore_index=True)

Expand Down Expand Up @@ -645,7 +644,6 @@ def groupby_with_null(data, *args, **kwargs):
# Groupby on the columns, making sure to revert back
# to NaN/None and the correct dtype.
for group, df in data.groupby(*args, **kwargs):
df.is_copy = None
for col, (orig_idx, orig_dtype) in altered_columns.items():
# Indices in the grouped df that need correction
sub_idx = orig_idx.intersection(df[col].index)
Expand Down

0 comments on commit 9b068b4

Please sign in to comment.