Skip to content

feat: update plot sample to 1000 rows #458

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

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bigframes/operations/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import matplotlib.pyplot as plt

DEFAULT_SAMPLING_N = 1000
DEFAULT_SAMPLING_STATE = 0


class MPLPlot(abc.ABC):
@abc.abstractmethod
Expand Down Expand Up @@ -45,8 +48,10 @@ def generate(self) -> None:

def _compute_plot_data(self, data):
# TODO: Cache the sampling data in the PlotAccessor.
sampling_n = self.kwargs.pop("sampling_n", 100)
sampling_random_state = self.kwargs.pop("sampling_random_state", 0)
sampling_n = self.kwargs.pop("sampling_n", DEFAULT_SAMPLING_N)
sampling_random_state = self.kwargs.pop(
"sampling_random_state", DEFAULT_SAMPLING_STATE
)
return data.sample(
n=sampling_n,
random_state=sampling_random_state,
Expand Down
8 changes: 4 additions & 4 deletions tests/system/small/operations/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pandas._testing as tm
import pytest

import bigframes.operations._matplotlib.core as bf_mpl
import bigframes.pandas as bpd


Expand Down Expand Up @@ -209,19 +210,18 @@ def test_scatter(scalars_dfs):


def test_sampling_plot_args_n():
df = bpd.DataFrame(np.arange(1000), columns=["one"])
df = bpd.DataFrame(np.arange(bf_mpl.DEFAULT_SAMPLING_N * 10), columns=["one"])
ax = df.plot.line()
assert len(ax.lines) == 1
# Default sampling_n is 100
assert len(ax.lines[0].get_data()[1]) == 100
assert len(ax.lines[0].get_data()[1]) == bf_mpl.DEFAULT_SAMPLING_N

ax = df.plot.line(sampling_n=2)
assert len(ax.lines) == 1
assert len(ax.lines[0].get_data()[1]) == 2


def test_sampling_plot_args_random_state():
df = bpd.DataFrame(np.arange(1000), columns=["one"])
df = bpd.DataFrame(np.arange(bf_mpl.DEFAULT_SAMPLING_N * 10), columns=["one"])
ax_0 = df.plot.line()
ax_1 = df.plot.line()
ax_2 = df.plot.line(sampling_random_state=100)
Expand Down