Add D3_to_df utility to put 3D output into a Pandas DataFrame - #1226
Open
arihantlodha-cmd wants to merge 1 commit into
Open
arihantlodha-cmd wants to merge 1 commit into
arihantlodha-cmd wants to merge 1 commit into
Conversation
Closes PSLmodels#1009. Adds utils.D3_to_df, which reshapes a three dimensional (T x S x J) transition-path output array into a tidy DataFrame with a (Year, Age) MultiIndex and one column per ability type j. This makes it easier to use model output in other software (plotting, spreadsheets), where a panel layout is more convenient than a raw 3D NumPy array. The function validates that the requested key exists and that the selected array is three dimensional, raising ValueError otherwise. Adds tests for the reshape (shape, index labels, value round-trip) and both error cases.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1226 +/- ##
==========================================
+ Coverage 75.17% 75.23% +0.05%
==========================================
Files 24 24
Lines 6031 6045 +14
==========================================
+ Hits 4534 4548 +14
Misses 1497 1497
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this does
Closes #1009. Adds
utils.D3_to_df, which reshapes a three dimensional (T x S x J) transition-path output array into a tidy DataFrame with a (Year, Age) MultiIndex and one column per ability type j. This makes it easier to use model output in other software (plotting, spreadsheets), where a panel layout is more convenient than a raw 3D NumPy array.Follows the sketch in the issue, with input validation added: the function raises
ValueErrorif the requested key is not intpi_varsor the selected array is not three dimensional.Usage
Testing
Adds
test_D3_to_df(checks shape, index names, first/last year labels, and a value round-trip) andtest_D3_to_df_errors(missing key and non-3D array). Both pass;ruff checkandruff format --checkare clean.