Skip to content
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

fix: extra quote + enh: control over line visibility #72

Merged
merged 12 commits into from
Oct 13, 2017

Conversation

satra
Copy link
Contributor

@satra satra commented Sep 24, 2017

No description provided.

@coveralls
Copy link

coveralls commented Sep 24, 2017

Coverage Status

Changes Unknown when pulling 93e3f18 on satra:enh/line-visibility-control into ** on maartenbreddels:master**.

@coveralls
Copy link

coveralls commented Sep 27, 2017

Coverage Status

Changes Unknown when pulling 8a94290 on satra:enh/line-visibility-control into ** on maartenbreddels:master**.

@satra
Copy link
Contributor Author

satra commented Sep 27, 2017

@maartenbreddels - it would be awesome if you can review/merge this. the pattern itself can be extended to the other plot routines.

we are trying to simultaneously work on a set of domain specific widgets that depends on this.

@maartenbreddels
Copy link
Collaborator

Hi Satrajit,

thanks for your contributions. What about making this arguments to plot()?

cheers.

Maarten

@satra
Copy link
Contributor Author

satra commented Sep 27, 2017

@maartenbreddels - it seems like a decision as to where to bring up all these arguments. so if every ipv.Scatter argument was an argument to plot then it would be fine to make everything arguments to plot. i just didn't know what you were thinking w.r.t the general api.

another option is to call kwargs, scatter_kwargs then you won't run into the issue of replicating things whenever scatter changes.

@maartenbreddels
Copy link
Collaborator

I think every property of Scatter that makes sense for a function in pylab should be an argument, and kwargs should be used for something that doesn't make sense, but that you may want to set anyway.

What would renaming scatter_kwargs to kwargs do, can you explain the issue?

@satra
Copy link
Contributor Author

satra commented Sep 27, 2017

@maartenbreddels - i updated it i think to reflect what you are saying.

however, i also made some changes to the other scatter wrapper functions. mostly this has to do with consistency rather than domain conventions.

@satra
Copy link
Contributor Author

satra commented Sep 27, 2017

if domain conventions should be used, for-example marker instead of geo, perhaps the signature of scatter should be updated? i have no strong feelings either way on this.

@maartenbreddels
Copy link
Collaborator

Great work. I don't think the argument have to match one-to-one match what is in Scatter, but if they are useful the should be exposed. I'll give some feedback on the PR, that will make it clearer maybe I mean, great work 👍

Copy link
Collaborator

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the main question I have is whether we should have plot and scatter have the same argument, but different defaults, what do you think?

@@ -367,12 +367,12 @@ def plot(x, y, z, color=default_color, visible_lines=True, color_selected=None,
:param y: {y}
:param z: {z}
:param color: {color}
:param visible_lines: {visible_lines}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only expose 'visible'.

@@ -367,12 +367,12 @@ def plot(x, y, z, color=default_color, visible_lines=True, color_selected=None,
:param y: {y}
:param z: {z}
:param color: {color}
:param visible_lines: {visible_lines}
:param color_selected: {color_selected}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This arg would only make sense for scatter, unless we want plot and scatter to have the same arguments but different defaults, that may not be such a bad idea actually.

@@ -402,7 +402,7 @@ def scatter(x, y, z, color=default_color, size=default_size,
:param size: {size}
:param size_selected: like size, but for selected glyphs
:param color_selected: like color, but for selected glyphs
:param geo: {geo} Uses marker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say marker, in the Scatter widget I may also change this to marker.

:param vx: {x_dir}
:param vy: {y_dir}
:param vz: {z_dir}
:param vx: x_dir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satra
Copy link
Contributor Author

satra commented Sep 28, 2017

@maartenbreddels

So the main question I have is whether we should have plot and scatter have the same argument, but different defaults, what do you think?

kind of. perhaps the other way to state it is:

any argument of scatter that is set by plot/quiver/scatter should be exposed as a specific keyword in the definition of plot/quiver/scatter otherwise they cannot be modified by the user using kwargs.

i originally ran into it since i wanted to turn visibility off, i was drawing 5000+ lines of different lengths and the update was really slow.

i reverted some of those matlab/matplotlib names for now. i think it would be good to make scatter consistent with it.

@maartenbreddels
Copy link
Collaborator

any argument of scatter that is set by plot/quiver/scatter should be exposed as a specific keyword in the definition of plot/quiver/scatter otherwise they cannot be modified by the user using kwargs
i originally ran into it since i wanted to turn visibility off, i was drawing 5000+ lines of different lengths and the update was really slow.

Can you explain this, I'm not sure I follow you. Any argument not exposed by plot can simply be picked up by kwargs and passed on right?

@satra
Copy link
Contributor Author

satra commented Oct 8, 2017

@maartenbreddels - sorry this must have skipped my notification

Can you explain this, I'm not sure I follow you. Any argument not exposed by plot can simply be picked up by kwargs and passed on right?

not if that arg is defined as a separate keyword arg in the inner func. the reason pull-request is in place is because i was trying to set visible_lines=False in plot. however, because of the error noted below i could not.

hence the two options are to always expose any settable keyword that can be manipulated at both levels, but default it in the outer level. hope that makes sense.

def inner_func(a=1, b=2, c=3):
    pass

def outer_func(**kwargs):
    inner_func(a=2, **kwargs)

outer_func(a=3)

results in:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-81cbd0310f74> in <module>()
      5     inner_func(a=2, **kwargs)
      6 
----> 7 outer_func(a=3)

<ipython-input-1-81cbd0310f74> in outer_func(**kwargs)
      3 
      4 def outer_func(**kwargs):
----> 5     inner_func(a=2, **kwargs)
      6 
      7 outer_func(a=3)

TypeError: inner_func() got multiple values for keyword argument 'a'

@satra
Copy link
Contributor Author

satra commented Oct 11, 2017

@maartenbreddels - just a ping here in case you didn't get a chance to look at my response.

satra added 2 commits October 11, 2017 07:30
…ty-control

* upstream/master:
  Update README.md
  fix: plot_isosurface was calling marching cubes twice, and better steps for sliders
  support for jupyter lab 0.27
@maartenbreddels
Copy link
Collaborator

maartenbreddels commented Oct 11, 2017

Ok, I understand the issue better.
My feeling on this, is that for plotting a line you want different default than scatter, but not directly expose them as defaults in the function arguments (I mean, having connected=True is a good default, and it makes no sense to have connected=True in the function arguments as default, and on top of that you need to write a docstring to explain this).
However, I do recognise that there are 'crazy' situations where you do actually want to override these default.
What about the following pattern (simplified for clarity):

def plot(x, y, z, color='red', **kwargs):
  defaults = dict(connected=True, visible_markers=False)
  kwargs = dict(defaults, **kwargs)  # merge dicts, where kwargs get preference over defaults
  scatter = Scatter(x, y, z, color=color, **kwargs)

So the different defaults (the ones that make sense to hide, such as connected and visible_markers are kind of hidden, but possible to override.

@satra
Copy link
Contributor Author

satra commented Oct 11, 2017

@maartenbreddels - ah that was the previous proposal :)

see this deleted version here:

782aec3#diff-f865c2c721a2719a6169fd34dfb51bc5L373

i'm happy to change it back to that state.

@coveralls
Copy link

coveralls commented Oct 11, 2017

Coverage Status

Coverage remained the same at 61.021% when pulling 8499c8c on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

@satra
Copy link
Contributor Author

satra commented Oct 11, 2017

@maartenbreddels - made the adjustments.

@coveralls
Copy link

coveralls commented Oct 11, 2017

Coverage Status

Coverage decreased (-0.2%) to 60.842% when pulling 4ac044c on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

@coveralls
Copy link

coveralls commented Oct 11, 2017

Coverage Status

Coverage increased (+0.5%) to 61.538% when pulling 16fa729 on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

Copy link
Collaborator

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent 👍 , thanks for putting in unittests as well. Some minor comments, hope you don't mind the endless dragging, but I'd like to get this right.

defaults = dict(visible_lines=True, color_selected=None, size_selected=1,
size=1, connected=True, visible_markers=False)
kwargs = dict(defaults, **kwargs)
scatter_hdl = ipv.Scatter(x=x, y=y, z=z, color=color, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why rename do scatter_hdl? I don't know what hdl means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two reasons -

  1. while it technically works there is a name clash, scatter is a method as well. so there is a local vs global clash that i do not like.
  2. _hdl stands for "handle" since it's really a pointer to the object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point, but I don't abrvs that aren't std ;). I'd rather see s = ipv.Scatter(..), and for python it's always by reference so _hdl doesn't add information, except indeed preventing a possible name collision. my preference goes to s or scatter_object

@@ -389,20 +392,26 @@ def scatter(x, y, z, color=default_color, size=default_size, size_selected=defau
:param size: {size}
:param size_selected: like size, but for selected glyphs
:param color_selected: like color, but for selected glyphs
:param marker: {marker}
:param marker: Uses marker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replace this docstring (which is substituted by the snippets on top) by this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry that's part of an older segment of changes - will revert that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

size_selected=size_selected, geo=marker, selection=selection, **kwargs)
fig.scatters = fig.scatters + [scatter]
return scatter
if 'geo' in kwargs:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'geo' is used for the Scatter object, but I think marker is a better name, and for this API i chose marker, which is taking it's role.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'd remove this part, and simply use marker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since under the current formulation, kwargs go on to the scatter call, if someone does use geo it will result in a clash, since marker gets converted to geo. this simply says if some puts in geo it will overwrite marker

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets us remove this, and change to use geo->marker (or leave that for me to do)

if 'geo' in kwargs:
marker = kwargs['geo']
del kwargs['geo']
scatter_hdl = ipv.Scatter(x=x, y=y, z=z, color=color, size=size,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies here, why hdl?


@_docsubst
def quiver(x, y, z, u, v, w, size=default_size * 10, size_selected=default_size_selected * 10, color=default_color,
def quiver(x, y, z, u, v, w, size=default_size * 10,
size_selected=default_size_selected * 10, color=default_color,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should be running flake8 :)

return scatter
if 'geo' in kwargs:
marker = kwargs['geo']
del kwargs['geo']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, please just use marker and forget about geo. I think maybe we should change Scatter.geo to Scatter.marker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you changed Scatter.geo to Scatter.marker we can simplify some of this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

marker = kwargs['geo']
del kwargs['geo']
if 'vx' in kwargs or 'vy' in kwargs or 'vz' in kwargs:
raise KeyError('Please use u, v, w instead of vx, vy, vz')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be added, quiver had never vx etc as arguments, is we were doing some backward incompatible tricks this would make sense though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reasoning as before:

quiver(..., u=u, ..., vx=u) would be legal but bad. this just raises an exception to notify the user. all of this stems from the fact that any kwargs eventually gets passed to the lowest level scatter call.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, indeed!

del kwargs['geo']
if 'vx' in kwargs or 'vy' in kwargs or 'vz' in kwargs:
raise KeyError('Please use u, v, w instead of vx, vy, vz')
scatter_hdl = ipv.Scatter(x=x, y=y, z=z, vx=u, vy=v, vz=w,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well, please remove the _hdl suffix.

@satra
Copy link
Contributor Author

satra commented Oct 13, 2017

@maartenbreddels - updated, if things look you can merge and then do the marker/geo bit. i'll be offline for a bit.

@maartenbreddels maartenbreddels merged commit 476e202 into widgetti:master Oct 13, 2017
@maartenbreddels
Copy link
Collaborator

Excellent, thanks a lot, and thanks for your patience! 👍

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 61.64% when pulling 59411d4 on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

4 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 61.64% when pulling 59411d4 on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 61.64% when pulling 59411d4 on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 61.64% when pulling 59411d4 on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 61.64% when pulling 59411d4 on satra:enh/line-visibility-control into 771b769 on maartenbreddels:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants