Skip to content

auto mixin class for generating add_<graphic> methods - #248

Merged
kushalkolar merged 14 commits into
masterfrom
auto_mixin
Jul 5, 2023
Merged

auto mixin class for generating add_<graphic> methods#248
kushalkolar merged 14 commits into
masterfrom
auto_mixin

Conversation

@clewis7

@clewis7 clewis7 commented Jun 20, 2023

Copy link
Copy Markdown
Member

closes #157

@clewis7 clewis7 changed the title automixin class for generating add_<graphic> methods auto mixin class for generating add_<graphic> methods Jun 20, 2023
@clewis7

clewis7 commented Jun 20, 2023

Copy link
Copy Markdown
Member Author

automixin class generated looks good, but then when I go to use the methods I get errors with the Graphic classes not being defined even though I am importing them in the file

Comment thread fastplotlib/layouts/_base.py Outdated
Comment thread fastplotlib/layouts/_base.py Outdated
Comment thread fastplotlib/utils/add_graphics.py Outdated
Comment thread fastplotlib/utils/generate_add_methods.py Outdated
Comment thread fastplotlib/utils/add_graphics.py Outdated
Comment thread fastplotlib/utils/generate_add_methods.py Outdated
…port the class elsewhere, graphic names not being defined
@clewis7

clewis7 commented Jun 21, 2023

Copy link
Copy Markdown
Member Author

seem to be having some importing issues, not sure how to fix but the generated class should be looking better!

@clewis7

clewis7 commented Jun 21, 2023

Copy link
Copy Markdown
Member Author
Cell In[7], line 1
----> 1 plot.add_image(data=data)

File ~/repos/fastplotlib/fastplotlib/layouts/_add_graphic_mixin.py:168, in GraphicMethodsMixin.add_image(self, data, vmin, vmax, cmap, filter, isolated_buffer, *args, **kwargs)
    111 	def add_image(self, data: Any, vmin: int = None, vmax: int = None, cmap: str = 'plasma', filter: str = 'nearest', isolated_buffer: bool = True, *args, **kwargs) -> weakref.proxy(ImageGraphic):
    112 		"""
    113 	
    114         Create an Image Graphic
   (...)
    166         
    167 		"""
--> 168 		g = ImageGraphic(*args, **kwargs)
    169 		self.add_graphic(g)
    171 		return weakref.proxy(g)

TypeError: ImageGraphic.__init__() missing 1 required positional argument: 'data'

Comment thread fastplotlib/layouts/_subplot.py Outdated
Comment thread fastplotlib/utils/generate_add_methods.py Outdated
Comment thread fastplotlib/utils/generate_add_methods.py Outdated
Comment thread fastplotlib/layouts/_subplot.py
Comment thread fastplotlib/layouts/_subplot.py
@clewis7

clewis7 commented Jun 22, 2023

Copy link
Copy Markdown
Member Author

not sure what is happening, need to keep investigating, but it seems like the generated methods are not registering *args and **kwargs

if I do something like:

import fastplotlib as fpl
import numpy as np

data = np.random.rand(512, 512)

plot = fpl.Plot()

plot.add_image(data)

when I print the *args and **kwargs, I get an empty tuple and dictionary, respectively (even when I try with data=data as kwarg)

@clewis7

clewis7 commented Jun 26, 2023

Copy link
Copy Markdown
Member Author

The only way I could get the generated add_<graphic> methods to work was to include the non-default arguments (mainly data=data) in the instantiation of the given graphic for a method

all of the graphics have a non-default data arg except for text, which for now I just manually changed, will need to think of a long-term solution as more graphics are added

I think it has to do with the nature of a mixin class, both the mixin class and the graphic class expect the kwarg arg data and if it is not specified in the graphic instantiation in the mixin method then it is not getting the data arg at all regardless of how you pass it to the mixin graphic method

@clewis7
clewis7 marked this pull request as ready for review June 26, 2023 12:57
@clewis7

clewis7 commented Jun 26, 2023

Copy link
Copy Markdown
Member Author

I think maybe my screenshots will be different because of the things that you changed in recent PRs?

@clewis7
clewis7 marked this pull request as draft June 26, 2023 20:35
@clewis7
clewis7 marked this pull request as ready for review June 27, 2023 17:44
Comment thread fastplotlib/layouts/graphic_methods_mixin.py Outdated
Comment thread fastplotlib/utils/generate_add_methods.py
@kushalkolar

Copy link
Copy Markdown
Member

Actually let's just set the type annotation as the Graphic that is returned and put in the docstring that it always returns a proxy. I think that makes inspection tools and tab completion etc. to work properly, rather than putting them as proxy[Graphic]

@kushalkolar

Copy link
Copy Markdown
Member

last question, docstrings and tab completion work in jupyterlab?

@clewis7

clewis7 commented Jun 29, 2023

Copy link
Copy Markdown
Member Author

yeah, works for me!

@kushalkolar
kushalkolar merged commit 31105cb into master Jul 5, 2023
@kushalkolar
kushalkolar deleted the auto_mixin branch July 6, 2023 05:58
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.

auto-generate mixin class for Subplot to hold all the add_<graphic> methods

2 participants