Skip to content

Commit 9b068b4

Browse files
committed
Use context manager to stop warnings not is_copy
df.is_copy was deprecated.
1 parent b5fda5e commit 9b068b4

17 files changed

+7
-21
lines changed

plotnine/coords/coord.py

-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ def munch_data(data, dist):
204204
len(data)-1])
205205

206206
munched = data.loc[idx, data.columns.difference(['x', 'y'])]
207-
munched.is_copy = None
208207
munched['x'] = x
209208
munched['y'] = y
210209
munched.reset_index(drop=True, inplace=True)

plotnine/geoms/geom.py

-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def draw_layer(self, data, layout, coord, **params):
219219
for pid, pdata in data.groupby('PANEL'):
220220
if len(pdata) == 0:
221221
continue
222-
pdata.is_copy = None
223222
ploc = pid - 1
224223
panel_params = layout.panel_params[ploc]
225224
ax = layout.axs[ploc]
@@ -258,7 +257,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
258257
"""
259258
for _, gdata in data.groupby('group'):
260259
gdata.reset_index(inplace=True, drop=True)
261-
gdata.is_copy = None
262260
self.draw_group(gdata, panel_params, coord, ax, **params)
263261

264262
@staticmethod

plotnine/geoms/geom_abline.py

-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
6262

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

plotnine/geoms/geom_dotplot.py

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def stackdots(a):
9292
for j in range(int(c))]
9393
data = data.iloc[idx]
9494
data.reset_index(inplace=True, drop=True)
95-
data.is_copy = None
9695
# Next part will set the position of each dot within each stack
9796
# If stackgroups=TRUE, split only on x (or y) and panel;
9897
# if not stacking, also split by group

plotnine/geoms/geom_hline.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
5151

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

plotnine/geoms/geom_path.py

-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
8989
c = Counter(data['group'])
9090
counts = np.array([c[v] for v in data['group']])
9191
data = data[counts >= 2]
92-
data.is_copy = None
9392

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

114112
@staticmethod

plotnine/geoms/geom_point.py

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def draw_group(data, panel_params, coord, ax, **params):
3131
data = coord.transform(data, panel_params)
3232
units = 'shape'
3333
for _, udata in groupby_with_null(data, units):
34-
udata.is_copy = None
3534
udata.reset_index(inplace=True, drop=True)
3635
geom_point.draw_unit(udata, panel_params, coord,
3736
ax, **params)

plotnine/geoms/geom_ribbon.py

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def draw_group(data, panel_params, coord, ax, **params):
3939
raise PlotnineError(msg)
4040

4141
for _, udata in groupby_with_null(data, units):
42-
udata.is_copy = None
4342
udata.reset_index(inplace=True, drop=True)
4443
geom_ribbon.draw_unit(udata, panel_params, coord,
4544
ax, **params)

plotnine/geoms/geom_violin.py

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
5353
quantiles = params['draw_quantiles']
5454

5555
for _, df in data.groupby('group'):
56-
df.is_copy = None
57-
5856
# Find the points for the line to go all the way around
5957
df['xminv'] = (df['x'] - df['violinwidth'] *
6058
(df['x'] - df['xmin']))

plotnine/geoms/geom_vline.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def draw_panel(self, data, panel_params, coord, ax, **params):
5151

5252
for _, gdata in data.groupby('group'):
5353
gdata.reset_index(inplace=True)
54-
gdata.is_copy = None
5554
geom_segment.draw_group(gdata, panel_params,
5655
coord, ax, **params)
5756

plotnine/ggplot.py

+7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ def draw(self, return_ggplot=False):
181181
This method does not modify the original ggplot object. You can
182182
get the modified ggplot object with :py:`return_ggplot=True`.
183183
"""
184+
# Pandas deprecated is_copy, and when we create new dataframes
185+
# from slices we do not want complaints. We always uses the
186+
# new frames knowing that they are separate from the original.
187+
with pd.option_context('mode.chained_assignment', None):
188+
return self._draw(return_ggplot)
189+
190+
def _draw(self, return_ggplot=False):
184191
# Prevent against any modifications to the users
185192
# ggplot object. Do the copy here as we may/may not
186193
# assign a default theme

plotnine/guides/guide_legend.py

-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ def draw(self):
311311
# overlay geoms
312312
for gl in self.glayers:
313313
data = gl.data.iloc[i]
314-
data.is_copy = None
315314
da = gl.geom.draw_legend(data, da, gl.layer)
316315
drawings.append(da)
317316
themeable['legend_key'].append(drawings)

plotnine/positions/position_stack.py

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ def compute_panel(cls, data, scales, params):
7070
negative = data['ymax'] < 0
7171
neg = data.loc[negative]
7272
pos = data.loc[~negative]
73-
neg.is_copy = None
74-
pos.is_copy = None
7573

7674
if len(neg):
7775
neg = cls.collide(neg, params=params)

plotnine/stats/stat.py

-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ def compute_panel(cls, data, scales, **params):
299299

300300
stats = []
301301
for _, old in data.groupby('group'):
302-
old.is_copy = None
303302
new = cls.compute_group(old, scales, **params)
304303
unique = uniquecols(old)
305304
missing = unique.columns.difference(new.columns)

plotnine/stats/stat_bindot.py

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ def func(df):
198198
if params['drop']:
199199
data = data[data['count'] > 0]
200200
data.reset_index(inplace=True, drop=True)
201-
data.is_copy = None
202201

203202
if params['binaxis'] == 'x':
204203
data['x'] = data.pop('bincenter')

plotnine/stats/stat_smooth.py

-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def setup_data(self, data):
142142
"""
143143
data = data[np.isfinite(data['x']) &
144144
np.isfinite(data['y'])]
145-
data.is_copy = None
146145
return data
147146

148147
def setup_params(self, data):

plotnine/utils.py

-2
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ def groupby_apply(df, cols, func, *args, **kwargs):
610610
for _, d in df.groupby(cols):
611611
# function fn should be free to modify dataframe d, therefore
612612
# do not mark d as a slice of df i.e no SettingWithCopyWarning
613-
d.is_copy = None
614613
lst.append(func(d, *args, **kwargs))
615614
return pd.concat(lst, axis=axis, ignore_index=True)
616615

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

0 commit comments

Comments
 (0)