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 #9996Labels 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. DescriptionReacted by Leo Gallucci and Will Hill Activityadded 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, 2019tswast commented on Dec 18, 2019 ContributorAuthor More actions See:
|
"datetime64[ns]": "DATETIME", |
and
|
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. tswast commented 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. emkornfield commented on Dec 20, 2019 @tswast I think the short term fix would be to change datetime64 to TIMESTAMP instead of DATETIME HemangChothani commented on Dec 20, 2019 @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? emkornfield commented on Dec 20, 2019 @HemangChothani Can you try changing
|
"datetime64[ns]": "DATETIME", |
to be TIMESTAMP. HemangChothani commented on Dec 20, 2019
@emkornfield I have tried with the change and it's working fine.
…emkornfield commented on Dec 20, 2019 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. tswast commented 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. HemangChothani commented on Dec 23, 2019 @tswast Yes it works if i manually specify TIMESTAMP in the job_config. tswast commented on Dec 23, 2019 ContributorAuthor More actions OK, thanks. Since we have a workaround, I'll drop the priority to P2. 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, 2019tswast commented on Dec 30, 2019 ContributorAuthor More actions tswast commented on Dec 30, 2019 ContributorAuthor More actions Created draft PR #10028 to hopefully reproduce this issue in a system test. tswast commented on Jan 2, 2020 ContributorAuthor More actions tswast commented 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. tswast commented 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
tswast commented 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. tswast commented 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 tswast commented 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. tswast commented 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.
MetadataMetadataapi: 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. DevelopmentNo branches or pull requestsIssue actions
|