-
Notifications
You must be signed in to change notification settings - Fork 98
Improve pandas dataframe inspection #319
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
Merged
martinRenou
merged 2 commits into
jupyterlab-contrib:main
from
martinRenou:improve_df_inspect
Sep 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, still the same issue with this.
Running a profiler on inspecting a 10 rows x 500_000 columns I see this takes more than 6 seconds to run. When inspecting a 10 rows x 50_000_000 columns, laptop goes out of memory and crashes.
Without doing any memory_usage computation, inspection takes less than 10 ms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion though!
I wonder if we could add a small condition on the shape, if the shape is in the 10 thousands and more we don't compute the memory usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, what about using a lazy approximation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is still quite slow when there are many columns (500_000 here, 6.8 seconds to compute)
Note that this means adding 6.8 seconds of delay between each cell execution once the variable is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess we could use some kind of cache. I guess it is feasible to write a function giving a rough estimate with something like
x.dtypes.map(size_of).sum() * len(x)
wheresize_of
would take thedtype
and compute it's size or return one from cache.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mapping over all the columns with
x.dtypes.map
will still be quite slow with a dataframe with lots of columns. Also invalidating cache may be hard?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be rather fast. You cloud do something like:
The harder part is implementing
size_of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be fine if, in this PR, I just add a watchdog that does:
And we can open a follow-up issue for a faster calculation of the memory usage, pointing to this discussion?
This would at least fix the crashing issue we're seeing on our side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, souds fine!