GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add max_results option to QueryJob.to_dataframe and QueryJob.to_arrow methods · Issue #296 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Add max_results option to QueryJob.to_dataframe and QueryJob.to_arrow methods #296

Copy link
Copy link
Closed
#698
Closed
Add max_results option to QueryJob.to_dataframe and QueryJob.to_arrow methods#296
#698
Copy link
Assignees
plamut
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@tswast
tswast
opened on Oct 5, 2020
Issue body actions

Currently, pandas-gbq calls QueryJob.result() and Client.list_rows() directly

https://github.com/pydata/pandas-gbq/blob/46c579ac21879b431c8568b49e68624f4a5ea25e/pandas_gbq/gbq.py#L561-L564

This is because the max_results parameter is needed, but not available in to_dataframe.

Currently, this is not a problem except for some duplicate code, but it may keep pandas-gbq from benefiting from the "fast query path" changes currently being designed.

Activity

  1. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    on Oct 5, 2020
  2. meredithslota
    added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Oct 5, 2020
  3. tswast
    changed the title [-]Add max_results option to to_dataframe methods[/-] [+]Add max_results option to to_dataframe and to_arrow methods[/+] on Nov 10, 2020
  4. plamut
    self-assigned this
    on Jun 10, 2021
  5. plamut commented on Jun 10, 2021

    @plamut
    plamut
    on Jun 10, 2021
    Contributor
    More actions

    @tswast Isn't max_results already set when a query job is created? If one then says:

    rows_iterator = query_job.result()
    rows_iterator.to_dataframe(max_results=42)

    The max_results argument should override the same setting on the query job? And stop iterating through pages/rows once that many rows have been fetched and yielded to the user code?

    Also, max_results is not compatible with BQ Storage client, thus if that is used, the code should just fall back to the REST API with a warning?

  6. tswast commented on Jun 10, 2021

    @tswast
    tswast
    on Jun 10, 2021
    ContributorAuthor
    More actions

    The max_results argument should override the same setting on the query job?

    I don't see max_results here?

    python-bigquery/google/cloud/bigquery/client.py

    Lines 3140 to 3150 in 790d11b

    def query(
    self,
    query: str,
    job_config: QueryJobConfig = None,
    job_id: str = None,
    job_id_prefix: str = None,
    location: str = None,
    project: str = None,
    retry: retries.Retry = DEFAULT_RETRY,
    timeout: float = None,
    ) -> job.QueryJob:

    Also, max_results is not compatible with BQ Storage client, thus if that is used, the code should just fall back to the REST API with a warning?

    I'm pretty sure that's the current behavior.

    rows_iterator.to_dataframe(max_results=42)

    Oh! No, I didn't mean here. I meant on the QueryJob. There's a QueryJob.to_dataframe() method and a QueryJob.to_arrow() method that call result(). I'd like them to be able to pass a max_results to that.

  7. tswast
    changed the title [-]Add max_results option to to_dataframe and to_arrow methods[/-] [+]Add max_results option to QueryJob.to_dataframe and QueryJob.to_arrow methods[/+] on Jun 10, 2021
  8. tswast commented on Jun 10, 2021

    @tswast
    tswast
    on Jun 10, 2021
    ContributorAuthor
    More actions

    (Looking at this, probably the solution in pandas-gbq is to call .result() with a max_results argument. Not sure why we weren't doing that.)

  9. plamut commented on Jun 10, 2021

    @plamut
    plamut
    on Jun 10, 2021
    Contributor
    More actions

    Ah, sorry, I meant the row iterator, yes.

    (Looking at this, probably the solution in pandas-gbq is to call .result() with a max_results argument. Not sure why we weren't doing that.)

    I thought there was a reason for that in Pandas GBQ and that you wanted to pass max_results later to the rows iterator returned by query_job.result() 😆

    Looks like we are almost set then, we just need to make sure that max_results is passed to query_job.result() even when the latter is called indirectly, e.g. through query_job.to_dataframe().

  10. plamut
    closed this as completedin #698on Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @plamut
    plamut

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.