Uploads a Pandas DataFrame to S3 as a parquet file Args: s3_resource: S3 Resource object s3_path: S3 path where the Parquet file is temporarily uploaded df: The Pandas DataFrame to upload Returns: None
(
s3_resource,
s3_path: str,
df: pd.DataFrame,
)
| 184 | |
| 185 | |
| 186 | def upload_df_to_s3( |
| 187 | s3_resource, |
| 188 | s3_path: str, |
| 189 | df: pd.DataFrame, |
| 190 | ) -> None: |
| 191 | """Uploads a Pandas DataFrame to S3 as a parquet file |
| 192 | |
| 193 | Args: |
| 194 | s3_resource: S3 Resource object |
| 195 | s3_path: S3 path where the Parquet file is temporarily uploaded |
| 196 | df: The Pandas DataFrame to upload |
| 197 | |
| 198 | Returns: None |
| 199 | |
| 200 | """ |
| 201 | bucket, key = get_bucket_and_key(s3_path) |
| 202 | |
| 203 | # Drop the index so that we dont have unnecessary columns |
| 204 | df.reset_index(drop=True, inplace=True) |
| 205 | |
| 206 | table = pa.Table.from_pandas(df) |
| 207 | # Write the PyArrow Table on disk in Parquet format and upload it to S3 |
| 208 | with tempfile.TemporaryDirectory() as temp_dir: |
| 209 | file_path = f"{temp_dir}/{uuid.uuid4()}.parquet" |
| 210 | pq.write_table(table, file_path) |
| 211 | s3_resource.Object(bucket, key).put(Body=open(file_path, "rb")) |
| 212 | |
| 213 | |
| 214 | def upload_df_to_redshift( |
nothing calls this directly
no test coverage detected