-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix: make to_pandas override enable_downsampling when sampling_method is manually set. #200
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
423db29
fix: make to_pandas override enable_downsampling when sampling_method…
Genesis929 d28a178
fix: make to_pandas override enable_downsampling when sampling_method…
Genesis929 ced1e4e
fix: make to_pandas override enable_downsampling when sampling_method…
Genesis929 fe22655
Merge branch 'main' into b310741105-to-pandas-downsampling
Genesis929 b230bb8
Merge branch 'main' into b310741105-to-pandas-downsampling
Genesis929 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,23 +389,6 @@ def to_pandas( | |
ordered: bool = True, | ||
) -> Tuple[pd.DataFrame, bigquery.QueryJob]: | ||
"""Run query and download results as a pandas DataFrame.""" | ||
if max_download_size is None: | ||
max_download_size = bigframes.options.sampling.max_download_size | ||
if sampling_method is None: | ||
sampling_method = ( | ||
bigframes.options.sampling.sampling_method | ||
if bigframes.options.sampling.sampling_method is not None | ||
else _UNIFORM | ||
) | ||
if random_state is None: | ||
random_state = bigframes.options.sampling.random_state | ||
|
||
sampling_method = sampling_method.lower() | ||
if sampling_method not in _SAMPLING_METHODS: | ||
raise NotImplementedError( | ||
f"The downsampling method {sampling_method} is not implemented, " | ||
f"please choose from {','.join(_SAMPLING_METHODS)}." | ||
) | ||
|
||
df, _, query_job = self._compute_and_count( | ||
value_keys=value_keys, | ||
|
@@ -453,6 +436,28 @@ def _compute_and_count( | |
) -> Tuple[pd.DataFrame, int, bigquery.QueryJob]: | ||
"""Run query and download results as a pandas DataFrame. Return the total number of results as well.""" | ||
# TODO(swast): Allow for dry run and timeout. | ||
enable_downsampling = ( | ||
True | ||
if sampling_method is not None | ||
else bigframes.options.sampling.enable_downsampling | ||
) | ||
|
||
max_download_size = ( | ||
max_download_size or bigframes.options.sampling.max_download_size | ||
) | ||
|
||
random_state = random_state or bigframes.options.sampling.random_state | ||
|
||
if sampling_method is None: | ||
sampling_method = bigframes.options.sampling.sampling_method or _UNIFORM | ||
sampling_method = sampling_method.lower() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you put sampling_method logic together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
if sampling_method not in _SAMPLING_METHODS: | ||
raise NotImplementedError( | ||
f"The downsampling method {sampling_method} is not implemented, " | ||
f"please choose from {','.join(_SAMPLING_METHODS)}." | ||
) | ||
|
||
expr = self._apply_value_keys_to_expr(value_keys=value_keys) | ||
|
||
results_iterator, query_job = expr.start_query( | ||
|
@@ -469,7 +474,7 @@ def _compute_and_count( | |
) | ||
|
||
if fraction < 1: | ||
if not bigframes.options.sampling.enable_downsampling: | ||
if not enable_downsampling: | ||
raise RuntimeError( | ||
f"The data size ({table_size:.2f} MB) exceeds the maximum download limit of " | ||
f"{max_download_size} MB. You can:\n\t* Enable downsampling in global options:\n" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: less code:
max_download_size = max_download_size or bigframes.options.sampling.max_download_size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done