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

Avoid setting batched before the class is initialized #5814

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Jul 19, 2023

@hoxbro feel free to reject this PR since it's not a fix per say.

What used to happen is showed in the example below, where the batched Parameter of GenericOverlayPlot was set (self.batched = batched) before Parameterized.__init__ was called. Setting a Parameter value before a Parameterized class is initialized (at the Param sense) has been supported somehow in Param for a long time. holoviz/param#766 broke that support temporarily, while holoviz/param#790 is an attempt at restoring it before Param 2.0 is released. Breaking that support temporarily allowed me to spot that this batched case was the only occurrence of a Parameter value being set early across a few code bases (Panel, Lumen, HoloViews). Because of that, and because it feels to me like an anti-pattern, I was tempted to open this PR to avoid this,

class GenericElementPlot(param.Parameterized):

    ....

    def __init__(self, batched=False, **params):
        self.batched = batched
        super().__init__(**params)

class GenericOverlayPlot(GenericElementPlot):

    ...

    batched = param.Boolean()

    def __init__(self, batched=True, **params):
        super().__init__(batched=batched, **params)

# When GenericOverlayPlot is instantiated `batched` is set before `Parameterized.__init__` is called.
GenericOverlayPlot()

@hoxbro
Copy link
Member

hoxbro commented Jul 19, 2023

Could we do something like this;

class GenericElementPlot(param.Parameterized):
    batched = param.Boolean(default=False)

    def __init__(self, **params):
        if param.get("batched"):
            ...
        super().__init__(**params)


class GenericOverlayPlot(GenericElementPlot):
    batched = param.Boolean(default=True)

    def __init__(self, **params):
        super().__init__(**params)

I also think it is an anti-pattern, and I will maybe go even further and say it is an anti-pattern that batched sometimes is a parameter, and sometimes it is not.

@hoxbro hoxbro added this to the 1.17.0 milestone Jul 19, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2023

Codecov Report

Merging #5814 (1b5acf1) into main (003be41) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5814      +/-   ##
==========================================
- Coverage   88.17%   88.15%   -0.03%     
==========================================
  Files         307      307              
  Lines       62916    62916              
==========================================
- Hits        55479    55466      -13     
- Misses       7437     7450      +13     
Flag Coverage Δ
ui-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
holoviews/plotting/plot.py 93.51% <100.00%> (ø)

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@maximlt
Copy link
Member Author

maximlt commented Jul 19, 2023

I also thought about adding batched as a Parameter to GenericElementPlot. Then I think I got confused by self.batched = batched being in between of other non Parameter attributes being set like zorder, cyclic_index or overlay_dims and wondered if it made sense for batched to be made more "officially" an input of GenericElementPlot while it seems to be dedicated to handle specifically NdOverlays?

@hoxbro hoxbro merged commit 2138f4f into main Jul 19, 2023
14 checks passed
@hoxbro hoxbro deleted the not_set_before_super branch July 19, 2023 14:33
@jbednar
Copy link
Member

jbednar commented Aug 16, 2023

I also thought about adding batched as a Parameter to GenericElementPlot.

I agree that it's very strange to have GenericElementPlot accept and respect batched without batched being a Parameter on GenericElementPlot, only its subclass. Seems very fishy and it's hard to see any justification for doing that. I agree it's truly bizarre that generally GEP has only a batched attribute except that sometimes it has a batched Parameter (if it's also a GenericOverlayPlot).

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.

4 participants