Skip to content

Addressing #40781 to raise ValueError as per discussion when a list with xlim or ylim is supplied, that contains elements in other format than integer or float type. #40886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ Plotting
- Prevent warnings when matplotlib's ``constrained_layout`` is enabled (:issue:`25261`)
- Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``yerr`` while others didn't (partial fix of :issue:`39522`)
- Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``secondary_y`` and others use ``legend=False`` (:issue:`40044`)

- Bug in :func:`DataFrame.plot.line` was taking ``xlim`` and ``ylim`` kwargs even if they had string elements, now ``ValueError`` is raised if elements are not ``int`` or ``float`` dtype.

Groupby/resample/rolling
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
17 changes: 15 additions & 2 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,30 @@ def _adorn_subplots(self):
)

for ax in self.axes:

if self.yticks is not None:
ax.set_yticks(self.yticks)

if self.xticks is not None:
ax.set_xticks(self.xticks)

if self.ylim is not None:
ax.set_ylim(self.ylim)
for elem in self.ylim: #Addressing issue #40781 raising ValueError if provided data type is not float or int.
if not is_float(elem) and not is_integer(elem):
raise ValueError(
"`ylim` should contain y-Axis plot range in either float or integer datatype.\n"
f"`ylim` had unsupported datatype of {type(elem)} with value {elem}. \n"
)
ax.set_ylim(self.ylim)

if self.xlim is not None:
ax.set_xlim(self.xlim)
for elem in self.xlim: #Addressing issue #40781 raising ValueError if provided data type is not float or int.
if not is_float(elem) and not is_integer(elem):
raise ValueError(
"`xlim` should contain y-Axis plot range in either float or integer datatype.\n"
f"`xlim` had unsupported datatype of {type(elem)} with value {elem}.\n"
)
ax.set_xlim(self.xlim)

# GH9093, currently Pandas does not show ylabel, so if users provide
# ylabel will set it as ylabel in the plot.
Expand Down