-
Notifications
You must be signed in to change notification settings - Fork 701
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
read_parquet function takes up a lot of memory even before it returns the iterable object #3010
Comments
Hi @geetparekh, note the rows in the parquet datasets are organized in row groups, and rows within a row group must be read in one go. The assumption that
The parquet file used for the test has 14092413 in 216 row groups:
Reading with I will continue doing some tests to reproduce your issue and keep you updated. Possibly related to |
Thank you @kukushking for explaining that. Our parquet file only has one row group. So, that kind of explains that the function would try to load the whole file in memory in our case. Would definitely suggest to explicitly add that in the documentation so that the users would know about it. |
On that note, you can possibly also consider including an example in the documentation explaining what all would be loaded in memory given an example of number of row groups in the parquet file and the chunk size requested. For example, if a parquet file has 100K records with 100 row groups (for simplicity), each row group would roughly have 1000 rows. If the requested chunk size is 5000, the function will end up loading 5 row groups in memory before returning the iterable object? |
Hey @geetparekh, @kukushking I also ran into this issue also with a chunksize of 100000. I figured out that the parquet file is loaded completely before yielding the result of the chunk. So I've raised the PR #3016. With these changes the memory usage is reduced dramatically. Without the changes, I constantly ran out of memory. Would be nice, if you could review it soon and release a new patch version! Thanks in advance, |
Describe the bug
The documentation of read_parquet function suggests that using the 'chunked' argument makes the function memory friendly as it will return an iterable of dataframes instead of a regular dataframe. However, when tested with a 500MB parquet file, with chunked = 1, the function takes up more than 7GB memory even before returning the iterable object. That indicates the function is doing something underneath (possibly loading the file in memory) before being able to give back a streamable object.
If this an expected behavior, then the function unfortunately cannot be considered as memory-friendly as it ends up taking up a lot of memory, and the documentation should explicitly specify that so that the users would know what to expect. If it is not the expected behavior, then it is possibly a bug.
Sharing our code below:
Note that in the above, I have added a comment to share which part of the code takes up a lot of memory.
How to Reproduce
Run the read_parquet function for a relatively large parquet file in S3 and check how much memory it consumes (through a memory profiler) before giving back an iterable object.
Expected behavior
The function (as the documentation suggests) should not be taking up so much memory while trying to return an iterable of dataframes.
Your project
No response
Screenshots
No response
OS
Ubuntu 22.04
Python version
3.10.12
AWS SDK for pandas version
3.9.1
Additional context
Support Case ID: 172918156100319
The text was updated successfully, but these errors were encountered: