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

%sqlplot bar and pie charts #508

Merged
merged 44 commits into from
Jun 1, 2023
Merged

%sqlplot bar and pie charts #508

merged 44 commits into from
Jun 1, 2023

Conversation

mehtamohit013
Copy link

@mehtamohit013 mehtamohit013 commented May 23, 2023

Describe your changes

Added bar and pie chart to sqlplot

Issue number

Closes #417

Checklist before requesting a review


📚 Documentation preview 📚: https://jupysql--508.org.readthedocs.build/en/508/

@mehtamohit013 mehtamohit013 marked this pull request as ready for review May 24, 2023 19:29
@edublancas
Copy link

hey @jorisroovers, wanna take a look at this and share your feedback?

you can see an interactive demo here: https://binder.ploomber.io/v2/gh/mehtamohit013/jupysql/plot?urlpath=lab/tree/doc/api/magic-plot.md (scroll down to see the bar and pie chart examples)

Copy link

@yafimvo yafimvo left a comment

Choose a reason for hiding this comment

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

@mehtamohit013
added some comments.
also, please rebase.

doc/api/magic-plot.md Outdated Show resolved Hide resolved
doc/api/magic-plot.md Outdated Show resolved Hide resolved
src/sql/magic_plot.py Outdated Show resolved Hide resolved
src/sql/magic_plot.py Show resolved Hide resolved
src/sql/magic_plot.py Outdated Show resolved Hide resolved
src/sql/plot.py Outdated Show resolved Hide resolved
src/sql/plot.py Outdated Show resolved Hide resolved
src/tests/test_magic_plot.py Outdated Show resolved Hide resolved
src/tests/test_magic_plot.py Outdated Show resolved Hide resolved
src/tests/test_magic_plot.py Show resolved Hide resolved
@jorisroovers
Copy link

hey @jorisroovers, wanna take a look at this and share your feedback?

Looking pretty good. Some feedback from spending a few mins...

  1. Pie chart: Would be good if there was an option to show the values (and percentages) inside or parts of the pie chart (or next to it with legend, probably easier to get right with edge cases).

  2. Pie chart: I would show the pie pieces in order of the query result (i.e. let the user decide) and not always order by size.

  3. Bar chart: x label looks off

image
  1. Bar chart: Also would be good to show exact number of each bar (inside bar) or in (optional) legend.

@mehtamohit013
Copy link
Author

mehtamohit013 commented May 25, 2023

@edublancas

  • For 1 and 4 added an additional argument -sn/--show_num to display the number and percentage
  • Fixed 3

You can test out the above changes on binder

  • Can you please elaborate on the 2nd point, I don't quite get it?

@mehtamohit013
Copy link
Author

Waiting for #486 to merge

doc/api/magic-plot.md Show resolved Hide resolved
doc/api/magic-plot.md Show resolved Hide resolved

`-sn`/`--show_num` Show number on top of the bar

Barplot does not support NULL values, so let's remove them:

Choose a reason for hiding this comment

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

can we add support for NULL values? you can run a query to filter them first

Copy link
Author

Choose a reason for hiding this comment

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

Should I raise some warning when there is NULL?

Choose a reason for hiding this comment

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

good point. not a warnings.warn, but printing a message saying that we're removing NULLs makes sense

Copy link
Author

Choose a reason for hiding this comment

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

Should the message be printed only when there is NULL or a generic message?
Currently added a general message:

print(f"Removing NULLs, if there exists any from {column}")

Choose a reason for hiding this comment

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

i didn't think about this. we have two options

  1. check if there is a null (by querying the table). if so, show a message and filter them out
  2. embed the null filter in the existing SQL queries as a subquery - this will impact performance but I'm guessing most SQL engines are smart enough to just pass the data once

let's implement 2. this implies that we won't show any message to the user since we'll filter out NULLs all the time - so there's no point in showing a message. we can later optimize.

Copy link
Author

@mehtamohit013 mehtamohit013 May 31, 2023

Choose a reason for hiding this comment

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

@edublancas
Implemented 2 option + Generic null Message for info :

Sample SQL query:

select "{{x_}}" as x,
"{{height_}}" as height
from "{{table}}"
where "{{x_}}" is not null
and "{{height_}}" is not null;

doc/api/magic-plot.md Outdated Show resolved Hide resolved
doc/api/magic-plot.md Show resolved Hide resolved
src/sql/magic_plot.py Show resolved Hide resolved
src/sql/plot.py Outdated Show resolved Hide resolved
src/sql/plot.py Outdated Show resolved Hide resolved
src/sql/plot.py Outdated Show resolved Hide resolved
src/tests/test_magic_plot.py Show resolved Hide resolved
@yafimvo
Copy link

yafimvo commented May 28, 2023

Waiting for #486 to merge

@mehtamohit013 We shouldn't wait for the merge.

Also, I see you addressed some of the issues. Please mark the issues you have fixed as "resolved" so that it will be easier to review them again.

P.S please rebase

Removed print statement
@mehtamohit013
Copy link
Author

@yafimvo @edublancas
While running matplotlib image tests, they are passing locally, but not in Github actions, as they are generating a different image in GitHub actions, but I make sure I have the same version locally as well on Github actions i.e. 3.7.1

Any idea why this is happening?

@edublancas
Copy link

@yafimvo @edublancas While running matplotlib image tests, they are passing locally, but not in Github actions, as they are generating a different image in GitHub actions, but I make sure I have the same version locally as well on Github actions i.e. 3.7.1

Any idea why this is happening?

this has happened before. usually fonts are the problem (even if you have the same matplotlib version, the fonts might be different).

there's an option to ignore text while testing, if this doesn't fix the issue, it'll be a bit challenging to debug because we don't have access to the failed images (I just opened this: #543)

see if you can quickly fix this, @mehtamohit013. if not, let me know and we can block this, you can work on #543 and then we can resume this work

@yafimvo
Copy link

yafimvo commented May 30, 2023

@mehtamohit013 Try to use these images

test_magic_plot.zip

@mehtamohit013
Copy link
Author

Try to use these images

Thanks, @yafimvo, matplotlib tests are now working.
Btw, how do you get theses images?

@mehtamohit013
Copy link
Author

@edublancas
Ready for merge

@yafimvo
Copy link

yafimvo commented May 30, 2023

Thanks, @yafimvo, matplotlib tests are now working.
Btw, how do you get theses images?

@mehtamohit013 The images failed due to minor font-weight differences so I just created new base images with the expected font-weights.

Copy link

@edublancas edublancas left a comment

Choose a reason for hiding this comment

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

this is almost ready. just implement the NULL support and show a message to the user

Copy link

@edublancas edublancas left a comment

Choose a reason for hiding this comment

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

address the NULLs comment and add a unit test with some dataset that has NULLs

@mehtamohit013
Copy link
Author

@edublancas
Working on tests. Please don't review
Accidentally asked for a review. There is no such button as take review requests back 😅

@mehtamohit013
Copy link
Author

@edublancas
Ready for merge

@edublancas edublancas merged commit b8b4060 into ploomber:master Jun 1, 2023
@edublancas
Copy link

awesome work!

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.

adding bar and pie plot to %sqlplot
5 participants