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

Less hacky plotting classes #3209

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft

Less hacky plotting classes #3209

wants to merge 37 commits into from

Conversation

flying-sheep
Copy link
Member

@flying-sheep flying-sheep commented Aug 13, 2024

An attempt to make the plotting classes less weird

contains a descriptor to allow the DEFAULT_BLAH class attributes to still work.

@ilan-gold please take a preliminary look

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 95.08197% with 12 lines in your changes missing coverage. Please review.

Project coverage is 76.69%. Comparing base (7ae1216) to head (297ed30).

Files with missing lines Patch % Lines
src/scanpy/plotting/_utils.py 86.48% 5 Missing ⚠️
src/scanpy/plotting/_baseplot_class.py 95.50% 4 Missing ⚠️
src/scanpy/plotting/_dotplot.py 96.77% 2 Missing ⚠️
src/scanpy/plotting/_matrixplot.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3209      +/-   ##
==========================================
- Coverage   76.85%   76.69%   -0.16%     
==========================================
  Files         109      109              
  Lines       12554    12616      +62     
==========================================
+ Hits         9648     9676      +28     
- Misses       2906     2940      +34     
Flag Coverage Δ
76.69% <95.08%> (-0.16%) ⬇️

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

Files with missing lines Coverage Δ
src/scanpy/external/pl.py 32.63% <ø> (ø)
src/scanpy/plotting/_stacked_violin.py 85.85% <100.00%> (-0.55%) ⬇️
src/scanpy/plotting/_matrixplot.py 96.59% <96.42%> (-0.08%) ⬇️
src/scanpy/plotting/_dotplot.py 93.75% <96.77%> (-0.37%) ⬇️
src/scanpy/plotting/_baseplot_class.py 91.20% <95.50%> (+0.02%) ⬆️
src/scanpy/plotting/_utils.py 58.47% <86.48%> (+1.83%) ⬆️

... and 9 files with indirect coverage changes

Copy link
Contributor

@ilan-gold ilan-gold left a comment

Choose a reason for hiding this comment

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

Instead of explicit old all-caps defaults, could be possible it to make a lookup of properties -> old all-caps defaults? And then have some sort of __get_attr__ or __get_attribute__ do the lookup and use the default? This might also make typing a bit easier maybe? Not sure though, just a quick first pass

def vboundnorm(self) -> VBoundNorm:
return VBoundNorm(self.vmin, self.vmax, self.vcenter, self.norm)

# deprecated class vars
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deprecated? Because they are already set from elsewhere (the function-based API)?

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, why re-introduce?

Copy link
Contributor

Choose a reason for hiding this comment

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

So these are part of the public API, the idea being to get rid of these eventually? https://scanpy.readthedocs.io/en/stable/api/generated/classes/scanpy.pl.StackedViolin.html

Copy link
Member Author

@flying-sheep flying-sheep Aug 13, 2024

Choose a reason for hiding this comment

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

Yeah, the default would be accessible like default = Baseplot.cmap, and overridable in subclasses:

class DotPlot(BasePlot):
    cmap = "Blues"

or just by setting it on the instance.

Comment on lines +221 to 225
# TODO: this doesn’t make much sense
self.category_height, self.category_width = (
self.category_width,
self.category_height,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed needs some investigating (what's the counter-factual when we remove it?)

norm=norm,
**kwds,
)
DEFAULT_DOT_MAX: ClassVar[DefaultProxy[float | None]] = DefaultProxy("dot_max")
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunate that the types need to be duplicated i.e., dot_max: float | None and then here DEFAULT_DOT_MAX: ClassVar[DefaultProxy[float | None]]

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth creating type variables? Seems like that is more lines of code, though...

Base automatically changed from fix-style to main September 20, 2024 15:05
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.

2 participants