-
Notifications
You must be signed in to change notification settings - Fork 273
Skrub Add Estimated Memory Usage to TableReport #2153
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
Open
salam-alkaissi
wants to merge
14
commits into
skrub-data:main
Choose a base branch
from
salam-alkaissi:skrub-Salam-womenInTech
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3d8d5fa
Add notes
salam-alkaissi edc7dad
add estimated memory usage
salam-alkaissi e5f11aa
add to CHANGES.rst
salam-alkaissi c727ed6
update CHANGES
salam-alkaissi 2afd0f5
remove notes file
salam-alkaissi c8b4ce4
change on _table_report.py
salam-alkaissi 5b5fd62
change on _table_report.py
salam-alkaissi 6e5b286
Merge branch 'skrub-Salam-womenInTech' of https://github.com/salam-al…
salam-alkaissi f4b99e9
change on table_report
salam-alkaissi 339e41d
change on summarize.py
salam-alkaissi 8e96017
change on summarize py
salam-alkaissi bbb67da
update on summarize.py file
salam-alkaissi 4a047fa
update on summarize py
salam-alkaissi 63493cb
update on CHANGES.rst
salam-alkaissi 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| cd D:\skrub-women-in-tech | ||
|
|
||
| python -m venv env_skrub | ||
| .\env_skrub\Scripts\Activate.ps1 or source env_skrub/bin/activatepip install -e ".[dev]" | ||
|
MarieSacksick marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| cd skrub (package) | ||
|
|
||
| cd D:\skrub-women-in-tech | ||
| python -m pip install --upgrade pip | ||
| pip install -e ".[dev]" | ||
|
|
||
|
|
||
| pip install pre-commit (install) | ||
| pre-commit install (run) | ||
|
|
||
|
|
||
| Configure git blame | ||
| git config blame.ignoreRevsFile .git-blame-ignore-revs | ||
| (env_skrub) PS D:\skrub-women-in-tech> git config --get blame.ignoreRevsFile | ||
| .git-blame-ignore-revs | ||
|
|
||
|
|
||
| ==== | ||
| Run the test suite | ||
|
|
||
| pytest --pyargs skrub | ||
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,28 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| _N_TOP_ASSOCIATIONS = 1000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _memory_usage_kb(df): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if sbd.dataframe_module_name(df) == "pandas": | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| memory_usage_bytes = df.memory_usage(deep=False).sum() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| estimated_size = getattr(df, "estimated_size", None) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if estimated_size is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| memory_usage_bytes = estimated_size() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return memory_usage_bytes / 1024 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There is a dedicated method to differentiate functions between Pandas and Polars! I've reformatted your exact code to use it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _has_complex_objects(df): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Return True when pandas has object-dtype columns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| The memory estimate is less reliable for object-dtype columns, so we warn | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| as soon as any are present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if sbd.dataframe_module_name(df) != "pandas": | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return any(dtype == object for dtype in df.dtypes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def summarize_dataframe( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| df, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -77,6 +99,7 @@ def summarize_dataframe( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| "dataframe_module": sbd.dataframe_module_name(df), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "n_rows": n_rows, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "n_columns": n_columns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "memory_usage_kb": _memory_usage_kb(df), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
MarieSacksick marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| "columns": [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dataframe_is_empty": not n_rows or not n_columns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "plots_skipped": not with_plots, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -90,6 +113,11 @@ def summarize_dataframe( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if title is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary["title"] = title | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # detect complex objects that make memory estimates unreliable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary["memory_estimate_unreliable"] = _has_complex_objects(df) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary["memory_estimate_unreliable"] = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if order_by is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| df = sbd.sort(df, by=order_by) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary["order_by"] = order_by | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
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
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.