Close parquet writer properly in `push_to_hub`
{'login': 'lhoestq', 'id': 42851186, 'node_id': 'MDQ6VXNlcjQyODUxMTg2', 'avatar_url': 'https://avatars.githubusercontent.com/u/42851186?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/lhoestq', 'html_url': 'https://github.com/lhoestq', 'followers_url': 'https://api.github.com/users/lhoestq/followers', 'following_url': 'https://api.github.com/users/lhoestq/following{/other_user}', 'gists_url': 'https://api.github.com/users/lhoestq/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/lhoestq/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/lhoestq/subscriptions', 'organizations_url': 'https://api.github.com/users/lhoestq/orgs', 'repos_url': 'https://api.github.com/users/lhoestq/repos', 'events_url': 'https://api.github.com/users/lhoestq/events{/privacy}', 'received_events_url': 'https://api.github.com/users/lhoestq/received_events', 'type': 'User', 'site_admin': False}
[]
[]
['_The documentation is not available anymore as the PR was closed or merged._'
 '@lhoestq / @albertvillanova / @mariosasko \r\nI am facing the same scenario. Let me explain the situation point. I have a glue ETL job\r\n\r\n1--> My files are in parquet format and stored in AWS s3.\r\n2--> I am iterating a  loop for a data set where the same file name can occur with diffrent other data.\r\n3--> I read the parquet and saved it in a pandas data frame.\r\n4--> Done some operation on that data frame\r\n5--> upload the updated data frame into the S3 parquet file.  Below are code snippet what I am using to save the updated \r\n         data frame into parquet format and load into S3\r\n         `header_name_column_list = dict(data_frame)\r\n          header_list = []\r\n            for col_id, col_type in header_name_column_list.items():\r\n                header_list.append(pyarrow.field(col_id, pyarrow.string()))\r\n            table_schema = pyarrow.schema(header_list)\r\n            table = pyarrow.Table.from_pandas(data_frame, schema=table_schema, preserve_index=False)\r\n            writer = parquet.ParquetWriter(b_buffer, table.schema)\r\n            writer.write_table(table)\r\n            writer.close()\r\n            b_buffer.seek(0)\r\n            .....\r\n            ....\r\n           self.s3_client.upload_fileobj(\r\n                b_buffer,\r\n                self.bucket,\r\n                file_key,\r\n                ExtraArgs=extra_args)`\r\n\r\nBut when I executed the glue etl job, the first time it works properly and but in the next iteration, when I try to open the same file got that error.\r\n\r\n\r\n<html>\r\n<body>\r\n<!--StartFragment-->\r\n\r\nINFO:Iot-dsip-de-duplication-job:Dataframe uploaded: s3://abc/2022/07/12/file1_ft_20220714122108.3065_12345.parquet INFO:Iot-dsip-de-duplication-job:Sleep for 60 sec\r\nINFO:Iot-dsip-de-duplication-job:start after sleep\r\n.......................\r\n..........................\r\n..........................\r\nERROR:Iot-dsip-de-duplication-job:Failed to read data from parquet file s3://abc/2022/07/12/file1_ft_20220714122108.3065_12345.parquet, error is : Invalid: Parquet magic bytes not found in footer. Either the file is corrupted or this is not a parquet file.INFO:Iot-dsip-de-duplication-job:Empty dataframe found\r\n\r\n<!--EndFragment-->\r\n</body>\r\n</html>\r\n\r\nAny clue will be really helpful..I got stuck with this problem.']
{'url': 'https://api.github.com/repos/huggingface/datasets/pulls/4081', 'html_url': 'https://github.com/huggingface/datasets/pull/4081', 'diff_url': 'https://github.com/huggingface/datasets/pull/4081.diff', 'patch_url': 'https://github.com/huggingface/datasets/pull/4081.patch', 'merged_at': datetime.datetime(2022, 4, 1, 16, 16, 19)}
We don’t call writer.close(), which causes https://github.com/huggingface/datasets/issues/4077. It can happen that we upload the file before the writer is garbage collected and writes the footer.

I fixed this by explicitly closing the parquet writer.

Close https://github.com/huggingface/datasets/issues/4077.
{'url': 'https://api.github.com/repos/huggingface/datasets/issues/4081/reactions', 'total_count': 0, '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}