Skip to content

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

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

Merged
merged 14 commits into from
Jul 5, 2023
Merged

Conversation

clewis7
Copy link
Member

@clewis7 clewis7 commented Jun 20, 2023

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
Copy link
Member Author

clewis7 commented Jun 20, 2023

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

…port the class elsewhere, graphic names not being defined
@clewis7
Copy link
Member Author

clewis7 commented Jun 21, 2023

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

@clewis7
Copy link
Member Author

clewis7 commented Jun 21, 2023

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'

@clewis7
Copy link
Member Author

clewis7 commented Jun 22, 2023

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
Copy link
Member Author

clewis7 commented Jun 26, 2023

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
Copy link
Member Author

clewis7 commented Jun 26, 2023

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
@kushalkolar
Copy link
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
Member

last question, docstrings and tab completion work in jupyterlab?

@clewis7
Copy link
Member Author

clewis7 commented Jun 29, 2023

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy