Update Slider docs and type check slidermin and slidermax. #8134

Merged
merged 10 commits into from Feb 25, 2017

Conversation

Projects
None yet
4 participants
Contributor

heath730 commented Feb 23, 2017 edited

This addresses #7687.

  • I tried to improve the doc strings of the widgets.slider class using numpydoc format. Let me know if it should be handled differently or I missed something. I built the docs and it rendered cleaner than previously using the current version.

  • Raises a ValueError if the slidermin or slidermax objects are not a compatible type (None or hasattr( 'val')).

  • Adds a test to make sure exception is raised in appropriate cases.

As I was testing this I noticed that the initial value can be outside of the bounds, and it will not be updated until _update gets called. To correct this I wrapped the statements that ensure the value is within the provided bounds into a function and called it in the the constructor. Currently there is no validation on the bounds, but I would be willing to add that if you think it will help.

heath730 added some commits Feb 23, 2017

@heath730 heath730 DOC: numpydoc-ify widget.Slider. a4694a0
@heath730 heath730 Raise ValueError if slidermin/max incompatible. 36ad946
@heath730 heath730 Dry out bounds checking for reuse. f59028e
@heath730 heath730 Lint: tabs to spaces. 9f4258b
@heath730 heath730 Tests for widgets.Slider.
ffba7d9
lib/matplotlib/widgets.py
+ Notes
+ ----------
@tacaswell

tacaswell Feb 23, 2017

Owner

picky thing, too many -- here, should be same length as title.

@tacaswell

Conditional on fixing the docstring formatting.

Owner

tacaswell commented Feb 23, 2017

While you are working on this exercising all of the branches of the validation method would be good, but not worth holding this PR up over.

tacaswell added this to the 2.1 (next point release) milestone Feb 23, 2017

Contributor

heath730 commented Feb 23, 2017

Thanks @tacaswell. I addressed your comments in the recent commits. Let me know if I should squash some commits and rebase on master pre-merge.

lib/matplotlib/widgets.py
Do not allow the current slider to have a value less than
- `slidermin`
+ `slidermin.val`.
@WeatherGod

WeatherGod Feb 23, 2017

Member

slidermin.val? Is that some sort of special numpydoc thing?

@tacaswell

tacaswell Feb 23, 2017

Owner

It is just saying it looks at the attribute I think.

@WeatherGod

WeatherGod Feb 23, 2017

Member

Ah, I think I see what is going on here. This needs to be clearer. Perhaps, "Do not allow the slider to have a value less than the value of the other Slider slidermin."

Owner

tacaswell commented Feb 23, 2017

Fine as is, rebase/squash if you want (I do it most when I am embarrassed about a mistake I committed ;) ).

lib/matplotlib/widgets.py
+ dragging : bool, optional
+ If True the slider can be dragged by the mouse.
+ Default: True
@WeatherGod

WeatherGod Feb 23, 2017

Member

Do we have to do special formatting for things like True and None?

lib/matplotlib/widgets.py
+ -----
+ Additional kwargs are passed on to ``self.poly`` which is the
+ :class:`matplotlib.patches.Rectangle` that draws the slider
+ knob. See the :class:`matplotlib.patches.Rectangle` documentation for
@WeatherGod

WeatherGod Feb 23, 2017

Member

If you put a tilda before the matplotlib.patches.Rectangle, then the rendered docs will only have Rectangle, which makes things easier to read.

lib/matplotlib/widgets.py
+ Additional kwargs are passed on to ``self.poly`` which is the
+ :class:`matplotlib.patches.Rectangle` that draws the slider
+ knob. See the :class:`matplotlib.patches.Rectangle` documentation for
+ valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...).
@WeatherGod

WeatherGod Feb 23, 2017

Member

No need for ellipses when it is already "e.g.".

lib/matplotlib/widgets.py
+ if not self.closedmax:
+ return
+ val = self.slidermax.val
+ self.set_val(val)
@WeatherGod

WeatherGod Feb 23, 2017

Member

I think I would rather that this method returns the value. It can then be up to the caller what to do with it. Might make it more portable with the planned traitlets work.

@NelleV

Apart from my minor comments on docstring formatting, this looks good.

If you prefer, I am happy fixing those just before merging.

lib/matplotlib/widgets.py
- less than *slidermax*
-
- *dragging* : allow for mouse dragging on slider
+ Create a slider from *valmin* to *valmax* in axes *ax*. For the slider to
@NelleV

NelleV Feb 23, 2017

Contributor

Can you remove the "*" formatting?

lib/matplotlib/widgets.py
- The slider label
+ valinit : float, optional
+ The slider initial position.
+ Default: 0.5
@NelleV

NelleV Feb 23, 2017

Contributor

Can you add the default on the line that defines the parameter?
(note that it is currently not indented properly).

lib/matplotlib/widgets.py
- Used to format the slider value, fprint format string
+ valfmt : str, optional
+ Used to format the slider value, fprint format string.
+ Default: '%1.2f'
@NelleV

NelleV Feb 23, 2017

Contributor

Same (Can you add the default on the line that defines the parameter?)

lib/matplotlib/widgets.py
- Indicate whether the slider interval is closed on the bottom
+ closedmin : bool, optional
+ Indicate whether the slider interval is closed on the bottom.
+ Default: True
@NelleV

NelleV Feb 23, 2017

Contributor

Same (Can you add the default on the line that defines the parameter?)

lib/matplotlib/widgets.py
- Indicate whether the slider interval is closed on the top
+ closedmax : bool, optional
+ Indicate whether the slider interval is closed on the top.
+ Default: True
@NelleV

NelleV Feb 23, 2017

Contributor

Same (Can you add the default on the line that defines the parameter?)

lib/matplotlib/widgets.py
Do not allow the current slider to have a value less than
- `slidermin`
+ the value of the Slider `slidermin`.
+ Default: None
@NelleV

NelleV Feb 23, 2017

Contributor

Same (Can you add the default on the line that defines the parameter?)

lib/matplotlib/widgets.py
- `slidermax`
-
+ the value of the Slider `slidermax`.
+ Default: None
@NelleV

NelleV Feb 23, 2017

Contributor

Same (Can you add the default on the line that defines the parameter?)

lib/matplotlib/widgets.py
- if the slider can be dragged by the mouse
+ dragging : bool, optional
+ If True the slider can be dragged by the mouse.
+ Default: True
@NelleV

NelleV Feb 23, 2017

Contributor

Same (Can you add the default on the line that defines the parameter?)

lib/matplotlib/widgets.py
+ Additional kwargs are passed on to ``self.poly`` which is the
+ :class:`~matplotlib.patches.Rectangle` that draws the slider
+ knob. See the :class:`~matplotlib.patches.Rectangle` documentation for
+ valid property names (e.g., *facecolor*, *edgecolor*, *alpha*).
@NelleV

NelleV Feb 23, 2017

Contributor

Can you remove the "*"?

self.valmin = valmin
self.valmax = valmax
+ valinit = self._value_in_bounds(valinit)
@NelleV

NelleV Feb 23, 2017

Contributor

👍

Contributor

heath730 commented Feb 23, 2017

Thanks @NelleV, I made the changes you suggested where it was possible to fit the default listing on the same line. Let me know if there is anything else, I'd be happy to squash this down for you guys before merging especially all the nits/lints.

@NelleV

NelleV approved these changes Feb 24, 2017

I pushed some minor nitpicks. It looks good to me.
👍

thanks a lot for the work on this PR @heath730 !

NelleV changed the title from Update Slider docs and type check slidermin and slidermax. to [MRG+2] Update Slider docs and type check slidermin and slidermax. Feb 24, 2017

Contributor

heath730 commented Feb 24, 2017

Thanks! Going squash a couple of the doc commits and push once more.

heath730 and others added some commits Feb 23, 2017

@heath730 heath730 Doc nit. 9d3e5e1
@heath730 heath730 Improve test coverage. ea899aa
@heath730 heath730 Bounds check returns value. dc55f80
@NelleV @heath730 NelleV FIX nitpicks on docstring
325789a
@heath730 heath730 Fix: indent error
2b42285

@NelleV NelleV merged commit c3e65f1 into matplotlib:master Feb 25, 2017

5 checks passed

codecov/patch 82% of diff hit (target 80%)
Details
codecov/project/library 57.97% (+0.22%) compared to ba418fd
Details
codecov/project/tests 98.57% (target 97.9%)
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Contributor

NelleV commented Feb 25, 2017

Thanks @heath730 !

QuLogic changed the title from [MRG+2] Update Slider docs and type check slidermin and slidermax. to Update Slider docs and type check slidermin and slidermax. Feb 25, 2017

heath730 deleted the heath730:slider_updates branch Feb 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment