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 — BigQuery: DATETIME columns invalid when uploaded with `load_table_from_dataframe` · Issue #9996 · googleapis/google-cloud-python

BigQuery: DATETIME columns invalid when uploaded with load_table_from_dataframe #9996

New issue
Copy link
New issue
Copy link
Closed
#10028
Closed
BigQuery: DATETIME columns invalid when uploaded with load_table_from_dataframe#9996
#10028
Copy link
Assignees
tswast
Labels
api: bigqueryIssues related to the BigQuery API.backendpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@tswast
tswast
opened on Dec 18, 2019
Issue body actions

https://github.com/googleapis/google-cloud-python/issues/9920#issuecomment-566642042

Reacted by Leo Gallucci and Will Hill

Activity

  1. tswast
    assigned
    HemangChothani
    on Dec 18, 2019
  2. tswast
    added
    api: bigqueryIssues related to the BigQuery API.
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Dec 18, 2019
  3. tswast commented on Dec 18, 2019

    @tswast
    tswast
    on Dec 18, 2019
    ContributorAuthor
    More actions

    See:

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

    Line 55 in 2dabc2d

    "datetime64[ns]": "DATETIME",

    and

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

    Line 79 in 2dabc2d

    return pyarrow.timestamp("us", tz=None)

    The fix is likely to change the pyarrow type to ns to match pandas behavior. We'll definitely want a system test to verify the fix.

  4. tswast commented on Dec 18, 2019

    @tswast
    tswast
    on Dec 18, 2019
    ContributorAuthor
    More actions

    One thing to consider: the full range of DATETIME is not supported when nanosecond precision is used.

    We need to check the input precision and make sure it matches the Arrow precision we use.

  5. emkornfield commented on Dec 20, 2019

    @emkornfield
    emkornfield
    on Dec 20, 2019
    Contributor
    More actions

    @tswast I think the short term fix would be to change datetime64 to TIMESTAMP instead of DATETIME

  6. HemangChothani commented on Dec 20, 2019

    @HemangChothani
    HemangChothani
    on Dec 20, 2019
    Contributor
    More actions

    @tseaver pyarrow.timestamp("ns", tz=None) doesn't help to resolve the issue, I've also tried with manually generated files but unable to find the resolution, I'm not sure but there may be something related to the backend as well?

  7. emkornfield commented on Dec 20, 2019

    @emkornfield
    emkornfield
    on Dec 20, 2019
    Contributor
    More actions

    @HemangChothani Can you try changing

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

    Line 55 in 2dabc2d

    "datetime64[ns]": "DATETIME",
    to be TIMESTAMP.

  8. HemangChothani commented on Dec 20, 2019

    @HemangChothani
    HemangChothani
    on Dec 20, 2019 via email
    Contributor
    More actions
    @emkornfield I have tried with the change and it's working fine.
    …
    On Fri, 20 Dec, 2019, 11:12 PM emkornfield, ***@***.***> wrote: @HemangChothani <https://github.com/HemangChothani> Can you try changing https://github.com/googleapis/google-cloud-python/blob/2dabc2dcc606e3867e25fd86ede21614cdcaaa04/bigquery/google/cloud/bigquery/_pandas_helpers.py#L55 to be TIMESTAMP. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#9996?email_source=notifications&email_token=AMAR4JVARUKEPRM3BEOMRKLQZT7W7A5CNFSM4J4PDI62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHNT2MQ#issuecomment-568016178>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AMAR4JTTUGVZK6SBYMYVXVDQZT7W7ANCNFSM4J4PDI6Q> .
  9. emkornfield commented on Dec 20, 2019

    @emkornfield
    emkornfield
    on Dec 20, 2019
    Contributor
    More actions

    I'll let others chime in, but in the short term I think this might be a reasonable fix. The main downside is that it doesn't allow round-tripping "datetime64[ns]", but at least data is preserved.

  10. tswast commented on Dec 22, 2019

    @tswast
    tswast
    on Dec 22, 2019
    ContributorAuthor
    More actions

    If you manually specify TIMESTAMP in the job_config, does that work?

    I’d prefer to keep time zone less columns mapping to DATETIME and fix the conversion.

    Reacted by Will Hill
  11. HemangChothani commented on Dec 23, 2019

    @HemangChothani
    HemangChothani
    on Dec 23, 2019
    Contributor
    More actions

    @tswast Yes it works if i manually specify TIMESTAMP in the job_config.

  12. tswast commented on Dec 23, 2019

    @tswast
    tswast
    on Dec 23, 2019
    ContributorAuthor
    More actions

    OK, thanks. Since we have a workaround, I'll drop the priority to P2.

  13. tswast
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    and removed
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Dec 23, 2019
  14. tswast commented on Dec 30, 2019

    @tswast
    tswast
    on Dec 30, 2019
    ContributorAuthor
    More actions

    For system tests of this fix, I'd like to see supported types added to https://github.com/googleapis/google-cloud-python/blob/master/bigquery/samples/load_table_dataframe.py and the tests for that sample updated to read and verify the table data.

    I'll work on updating the tests for currently-supported data types.

  15. tswast commented on Dec 30, 2019

    @tswast
    tswast
    on Dec 30, 2019
    ContributorAuthor
    More actions

    Created draft PR #10028 to hopefully reproduce this issue in a system test.

  16. tswast commented on Jan 2, 2020

    @tswast
    tswast
    on Jan 2, 2020
    ContributorAuthor
    More actions

    I see in the unit tests for this that uploading DATETIME columns was blocked by https://issues.apache.org/jira/browse/ARROW-5450, so once this issue is fixed, we'll require the latest version of pyarrow to upload DATETIME columns.

  17. tswast
    assigned
    tswast
    and unassigned
    HemangChothani
    on Jan 2, 2020
  18. tswast commented on Jan 2, 2020

    @tswast
    tswast
    on Jan 2, 2020
    ContributorAuthor
    More actions

    I investigated this further by capturing the Parquet file that is generated by _pandas_helpers.dataframe_to_parquet.

    client.py

                if pyarrow and job_config.schema:
                    if parquet_compression == "snappy":  # adjust the default value
                        parquet_compression = parquet_compression.upper()
    
                    _pandas_helpers.dataframe_to_parquet(
                        dataframe,
                        job_config.schema,
                        tmppath,
                        parquet_compression=parquet_compression,
                    )
                    import shutil
                    shutil.copyfile(tmppath, "/Users/swast/Desktop/dataframe.parquet")
                else:
    

    dataframe.parquet.zip

    When I upload dataframe.parquet via the web interface, I'm not able to reproduce the issue. There must be something different with how we upload the data file from Python.

  19. tswast commented on Jan 2, 2020

    @tswast
    tswast
    on Jan 2, 2020
    ContributorAuthor
    More actions

    I'm able to reproduce this with the command-line:

    bq load --source_format=PARQUET --schema=wikidata_id:STRING,title:STRING,release_year:INTEGER,length_minutes:FLOAT,release_date:TIMESTAMP,dvd_release:DATETIME my_dataset.monty_python dataframe.parquet
    
  20. tswast
    added
    backend
    on Jan 2, 2020
  21. tswast commented on Jan 2, 2020

    @tswast
    tswast
    on Jan 2, 2020
    ContributorAuthor
    More actions

    Since I'm able to reproduce this error with the command-line, I believe it is a backend issue. I've filed internal bug 147108331 for the backend engineers to investigate.

  22. tswast commented on Jan 2, 2020

    @tswast
    tswast
    on Jan 2, 2020
    ContributorAuthor
    More actions

    I was able to create a Parquet file with nanosecond-precision DATETIME columns, but the backend still multiplies the values by 1000. It seems we can't write DATETIME columns from Parquet without a backend fix.

    dataframe_nanos.parquet.zip

  23. tswast commented on Jan 2, 2020

    @tswast
    tswast
    on Jan 2, 2020
    ContributorAuthor
    More actions

    After all this, I think the best option is to write datetime[ns] dtype columns as TIMESTAMP, since I'm not able to write correct DATETIME columns with parquet files. I've updated my draft PR with this workaround.

  24. tswast commented on Jan 8, 2020

    @tswast
    tswast
    on Jan 8, 2020
    ContributorAuthor
    More actions

    Talked with the backend engineers. DATETIME is not supported for uploading from Parquet (treating my request as a feature request), so changing the dtype to TIMESTAMP is the correct solution.

  25. plamut
    closed this as completedin #10028on Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tswast
    tswast

Labels

api: bigqueryIssues related to the BigQuery API.backendpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

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.