Skip to content

Commit ca59a3b

Browse files
changes based on reviews
1 parent 9f9e3da commit ca59a3b

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

pandas/plotting/_core.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def _kind(self):
8282
_default_rot = 0
8383
orientation = None
8484
_pop_attributes = ['label', 'style', 'logy', 'logx', 'loglog',
85-
'mark_right', 'stacked', 'sym']
85+
'mark_right', 'stacked']
8686
_attr_defaults = {'logy': False, 'logx': False, 'loglog': False,
87-
'mark_right': True, 'stacked': False, 'sym': False}
87+
'mark_right': True, 'stacked': False}
8888

8989
def __init__(self, data, kind=None, by=None, subplots=False, sharex=None,
9090
sharey=False, use_index=True,
@@ -308,16 +308,20 @@ def _setup_subplots(self):
308308

309309
axes = _flatten(axes)
310310

311-
if self.logx or self.loglog:
312-
if self.sym:
313-
[a.set_xscale('symlog') for a in axes]
314-
else:
315-
[a.set_xscale('log') for a in axes]
316-
if self.logy or self.loglog:
317-
if self.sym:
318-
[a.set_yscale('symlog') for a in axes]
319-
else:
320-
[a.set_yscale('log') for a in axes]
311+
valid_log = [False, True, 'sym']
312+
for i in [self.logx, self.logy, self.loglog]:
313+
if i not in valid_log:
314+
raise ValueError("Wrong input for log option.")
315+
316+
if self.logx is True or self.loglog is True:
317+
[a.set_xscale('log') for a in axes]
318+
elif self.logx == 'sym' or self.loglog == 'sym':
319+
[a.set_xscale('symlog') for a in axes]
320+
321+
if self.logy is True or self.loglog is True:
322+
[a.set_yscale('log') for a in axes]
323+
elif self.logy == 'sym' or self.loglog == 'sym':
324+
[a.set_yscale('symlog') for a in axes]
321325

322326
self.fig = fig
323327
self.axes = axes

pandas/tests/plotting/test_frame.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,40 @@ def test_plot_xy(self):
231231
@pytest.mark.slow
232232
def test_logscales(self):
233233
df = DataFrame({'a': np.arange(100)}, index=np.arange(100))
234+
234235
ax = df.plot(logy=True)
235236
self._check_ax_scales(ax, yaxis='log')
236-
ax = df.plot(logy=True, sym=True)
237+
assert ax.get_yscale() == 'log'
238+
239+
ax = df.plot(logy='sym')
237240
self._check_ax_scales(ax, yaxis='symlog')
241+
assert ax.get_yscale() == 'symlog'
238242

239243
ax = df.plot(logx=True)
240244
self._check_ax_scales(ax, xaxis='log')
241-
ax = df.plot(logx=True, sym=True)
245+
assert ax.get_xscale() == 'log'
246+
247+
ax = df.plot(logx='sym')
242248
self._check_ax_scales(ax, xaxis='symlog')
249+
assert ax.get_xscale() == 'symlog'
243250

244251
ax = df.plot(loglog=True)
245252
self._check_ax_scales(ax, xaxis='log', yaxis='log')
246-
ax = df.plot(loglog=True, sym=True)
253+
assert ax.get_xscale() == 'log'
254+
assert ax.get_yscale() == 'log'
255+
256+
ax = df.plot(loglog='sym')
247257
self._check_ax_scales(ax, xaxis='symlog', yaxis='symlog')
258+
assert ax.get_xscale() == 'symlog'
259+
assert ax.get_yscale() == 'symlog'
260+
261+
@pytest.mark.parametrize("wrong_input", ["sm", "symlog"])
262+
def test_invalid_logscale(self, wrong_input):
263+
df = DataFrame({'a': np.arange(100)}, index=np.arange(100))
264+
265+
msg = "Wrong input for log option."
266+
with pytest.raises(ValueError, match=msg):
267+
df.plot(logy=wrong_input)
248268

249269
@pytest.mark.slow
250270
def test_xcompat(self):

0 commit comments

Comments
 (0)