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: (Series|Dataframe).plot.hist() #420

Merged
merged 4 commits into from
Mar 11, 2024

Conversation

chelsea-lin
Copy link
Contributor

internal bug: b/322178004

@chelsea-lin chelsea-lin requested a review from tswast March 7, 2024 19:31
@chelsea-lin chelsea-lin requested review from a team as code owners March 7, 2024 19:31
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Mar 7, 2024
@chelsea-lin chelsea-lin force-pushed the main_chelsealin_hist_call_pandas branch from 06fb1e6 to 84f816d Compare March 7, 2024 20:17
@chelsea-lin chelsea-lin requested a review from orrbradford March 7, 2024 20:18
@chelsea-lin chelsea-lin force-pushed the main_chelsealin_hist_call_pandas branch from 84f816d to a2ac563 Compare March 7, 2024 20:51
bigframes/operations/_matplotlib/core.py Outdated Show resolved Hide resolved
import pandas as pd

import bigframes.constants as constants
from bigframes.operations._matplotlib.core import MPLPlot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks!

bigframes/operations/_matplotlib/hist.py Outdated Show resolved Hide resolved
)
kwargs["by"] = by
kwargs["bins"] = bins
return plotbackend.plot(self._parent.copy(), kind="hist", **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain a bit more in the comments what's going on here?

Do we need to add a TODO for supporting other plotbackends, for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment here. We may introduce other backends for interactive visualization support in the future.

@@ -58,6 +58,7 @@
"tabulate >= 0.9",
"ipywidgets >=7.7.1",
"humanize >= 4.6.0",
"matplotlib >= 3.7.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this to https://github.com/googleapis/python-bigquery-dataframes/blob/main/testing/constraints-3.10.txt too so that we know we always test against our advertised minimum version in at least one test session.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

matplotlib==3.7.1 has been added into this file earlier. The system-3.10 tests are not triggerred according to

SYSTEM_TEST_PYTHON_VERSIONS = ["3.9", "3.11"]

If so, should I add the matplotlib to contraints-3.9.txt also?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, you're right. Yes add to contraints-3.9.txt. I was looking at the list of files sorted alphabetically.

@@ -1557,6 +1558,10 @@ def __array_ufunc__(
def str(self) -> strings.StringMethods:
return strings.StringMethods(self._block)

@property
def plot(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Added PlotAccessor to the series.rst and frames.rst.
As for the docstring for def plot, it is defined at third_party/bigframes_vendored/pandas/core/series.py

@chelsea-lin chelsea-lin force-pushed the main_chelsealin_hist_call_pandas branch from a2ac563 to 82797de Compare March 11, 2024 21:33
@chelsea-lin chelsea-lin force-pushed the main_chelsealin_hist_call_pandas branch from 39b6c63 to e71d19c Compare March 11, 2024 21:47
.. automodule:: bigframes.operations.plotting
:members:
:inherited-members:
:undoc-members:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking! Fixed.


self.axes = hist_x_pd.plot.hist(
bins=bin_edges,
weights=np.array(weights_pd.values),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this method still not working on pandas 1.5 or did the fillna solve that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the fillna solves the issue in pandas 1.5. I can add a comment above calling.

@chelsea-lin chelsea-lin merged commit 4aadff4 into main Mar 11, 2024
14 of 15 checks passed
@chelsea-lin chelsea-lin deleted the main_chelsealin_hist_call_pandas branch March 11, 2024 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants