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

feat: plot1d for hist(cat,reg) #174

Merged
merged 5 commits into from
Apr 8, 2021
Merged

Conversation

andrzejnovak
Copy link
Member

Fixes #173.

I am kind of expecting to get shouted at for UHI abuse one way or another, but that's what I could piece from the docs on first run.

image

Copy link
Member

@henryiii henryiii left a comment

Choose a reason for hiding this comment

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

Mostly looks good!

src/hist/basehist.py Outdated Show resolved Hide resolved
Comment on lines 304 to 305
if self.ndim == 1:
len_cat = np.sum([ax.traits.discrete for ax in self.axes])
if self.ndim == 1 or (self.ndim == 2 and len_cat == 1):
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I like this. It's also valid to make a 2D plot where one axis is categorical (or two, for that matter). I think it would be more predictable if .plot() on a 2D histogram always made a 2D plot. But I could be convinced. What do other people think? @nsmith-, @matthewfeickert, perhaps?

Copy link
Member Author

@andrzejnovak andrzejnovak Apr 7, 2021

Choose a reason for hiding this comment

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

What @nsmith- 's coffea API does is have overlay keyword to control this for non-discrete axes, but if think the number of 2d histograms of type (sample, quantity) is gonna be higher than (quantity, quantity) at least if one of the axes is StrCat (or just Cat)

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose in coffea its either plot1d or plot2d. But indeed if overlay: Optional[str] is a parameter, one can take that to decide if a 2D hist is a 2D plot or a set of 1D plots with the overlay axis as specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option might be to follow pandas style, where the hist would have to be turned into some kind of HistGroupBy object before plotting, e.g. h.groupby("region").plot().

Copy link
Member Author

Choose a reason for hiding this comment

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

tbh since hist does plot1d() and plot2d() as well and plot() is just a two char shortcut, this is a trifle.

@nsmith- can you think of any other use for some kind of groupby fcn than this? I don't think it's worth fiddling with just for this

Copy link
Contributor

Choose a reason for hiding this comment

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

Not yet, probably you are right to leave it as-is for now.

@andrzejnovak
Copy link
Member Author

@henryiii should I try to make sourcery happy? otherwise this is ready for review I think

src/hist/basehist.py Outdated Show resolved Hide resolved
@henryiii
Copy link
Member

henryiii commented Apr 8, 2021

should I try to make sourcery happy

Only if it wants a sensible change (not always). If it's just the "guard" style if, I mildly like that, so if you are neutral, I'd go with that.

src/hist/basehist.py Outdated Show resolved Hide resolved
src/hist/basehist.py Outdated Show resolved Hide resolved
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
src/hist/basehist.py Outdated Show resolved Hide resolved
src/hist/basehist.py Outdated Show resolved Hide resolved
src/hist/basehist.py Outdated Show resolved Hide resolved
@henryiii henryiii changed the title feat: plo1d for hist(cat,reg) feat: plot1d for hist(cat,reg) Apr 8, 2021
@henryiii
Copy link
Member

henryiii commented Apr 8, 2021

@all-contributors please add @andrzejnovak for code

@allcontributors
Copy link
Contributor

@henryiii

I've put up a pull request to add @andrzejnovak! 🎉

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 8, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.12%.

Quality metrics Before After Change
Complexity 2.92 ⭐ 2.89 ⭐ -0.03 👍
Method Length 91.37 🙂 96.28 🙂 4.91 👎
Working memory 14.79 😞 14.61 😞 -0.18 👍
Quality 53.84% 🙂 53.96% 🙂 0.12% 👍
Other metrics Before After Change
Lines 960 1010 50
Changed files Quality Before Quality After Quality Change
src/hist/basehist.py 63.32% 🙂 62.38% 🙂 -0.94% 👎
tests/test_plot.py 48.10% 😞 48.80% 😞 0.70% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
src/hist/basehist.py BaseHist.__init__ 18 🙂 176 😞 14 😞 37.34% 😞 Try splitting into smaller methods. Extract out complex expressions
src/hist/basehist.py BaseHist.from_columns 14 🙂 160 😞 16 ⛔ 39.67% 😞 Try splitting into smaller methods. Extract out complex expressions
tests/test_plot.py test_general_plot1d.test_general_plot2d.test_general_plot2d_full.test_general_plot.test_named_plot1d.test_named_plot2d.test_named_plot2d_full.test_named_plot.test_named_plot_pull 0 ⭐ 369 ⛔ 16 ⛔ 42.53% 😞 Try splitting into smaller methods. Extract out complex expressions
tests/test_plot.py test_general_plot1d.test_general_plot2d.test_general_plot2d_full.test_general_plot.test_general_plot_pull 0 ⭐ 361 ⛔ 16 ⛔ 42.67% 😞 Try splitting into smaller methods. Extract out complex expressions
tests/test_plot.py test_general_plot1d.test_general_plot2d.test_general_plot2d_full.test_general_plot.test_named_plot1d.test_named_plot2d.test_named_plot2d_full.test_named_plot 0 ⭐ 246 ⛔ 20 ⛔ 43.21% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@andrzejnovak
Copy link
Member Author

@henryiii looks done then, let me know if you'd like me to squash the commits

@henryiii
Copy link
Member

henryiii commented Apr 8, 2021

Nah, that's fine, I usually squash and merge unless there's a need to leave more than one comment (like a moved and changed file, or a set of sequential steps).

Copy link
Member

@henryiii henryiii left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@henryiii henryiii merged commit da5a47d into scikit-hep:master Apr 8, 2021
@henryiii
Copy link
Member

henryiii commented Apr 8, 2021

I'll fill in the changelog later, to keep the PRs from colliding.

@henryiii
Copy link
Member

henryiii commented Apr 8, 2021

Thanks!!!

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.

[FEATURE] hist(StrCat, Reg) viz
4 participants