Skip to content

Commit

Permalink
add warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
chelsea-lin committed Nov 15, 2024
1 parent e7916d9 commit 86de62c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bigframes/operations/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import abc
import typing
import warnings

import bigframes_vendored.constants as constants
import pandas as pd
Expand Down Expand Up @@ -62,6 +63,15 @@ def generate(self) -> None:
def _compute_sample_data(self, data):
# TODO: Cache the sampling data in the PlotAccessor.
sampling_n = self.kwargs.pop("sampling_n", DEFAULT_SAMPLING_N)
if self._sampling_warning_msg is not None:
total_n = data.shape[0]
if sampling_n < total_n:
warnings.warn(
self._sampling_warning_msg().format(
sampling_n=sampling_n, total_n=total_n
)
)

sampling_random_state = self.kwargs.pop(
"sampling_random_state", DEFAULT_SAMPLING_STATE
)
Expand All @@ -74,6 +84,9 @@ def _compute_sample_data(self, data):
def _compute_plot_data(self):
return self._compute_sample_data(self.data)

def _sampling_warning_msg(self) -> str:
return None


class AreaPlot(SamplingPlot):
@property
Expand All @@ -86,6 +99,14 @@ class BarPlot(SamplingPlot):
def _kind(self) -> typing.Literal["bar"]:
return "bar"

def _sampling_warning_msg(self) -> str:
return (
"To optimize plotting performance, your data has been downsampled to {sampling_n} "
"rows from the original {total_n} rows. This may result in some data points "
"not being displayed. For a more comprehensive view, consider pre-processing "
"your data by aggregating it or selecting the top categories."
)


class LinePlot(SamplingPlot):
@property
Expand Down

0 comments on commit 86de62c

Please sign in to comment.