Skip to content
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

If petl is loaded from a CSV, use the source file, don't re-write #1062

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions parsons/google/google_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from parsons.google.utitities import setup_google_application_credentials
from parsons.utilities import files
import datetime
import gzip
import petl
import logging
import time
import uuid
import gzip
import zipfile
from typing import Optional

Expand Down Expand Up @@ -311,7 +312,14 @@ def upload_table(self, table, bucket_name, blob_name, data_type="csv", default_a
blob = storage.Blob(blob_name, bucket)

if data_type == "csv":
local_file = table.to_csv()
# If a parsons Table is loaded from a CSV and has had no
# transformations, the Table.table object will be a petl
# CSVView. Once any transformations are made, the Table.table
# becomes a different petl class
if isinstance(table.table, petl.io.csv_py3.CSVView):
local_file = table.table.source.filename
else:
local_file = table.to_csv()
content_type = "text/csv"
elif data_type == "json":
local_file = table.to_json()
Expand Down
Loading