-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Export Results as Dataframe #100
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
priyadarshini-ni
merged 18 commits into
master
from
users/priya/results-dataframe-utility
Mar 11, 2025
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c0dc98d
add files
46398ca
Merge branch 'master' of https://github.com/ni/nisystemlink-clients-p…
6800b0f
refactor:DataframeUtilitiesWithoutBatchQuery
RSam-NI 42460dc
remove batching
46eaa97
fix:PoeCheckError
RSam-NI ffbcceb
lint fix
8772a2f
fix:PRComments
sam-rishi 9200e70
merge:Origin
RSam-NI a5c6876
refactor:SetIDAsIndex
RSam-NI c8809f9
refactor:PRComments
RSam-NI 18bd82b
refactor:UnitTests
RSam-NI 138ecb7
Merge remote-tracking branch 'upstream/master' into users/priya/resul…
3781682
fix: resolve comments
ec3290b
reduce status to single column
adb9893
fix: format, types
b406089
refactor method
ae5d347
fix: method name
79f35dd
fix: format
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from ._dataframe_utilities import convert_results_to_dataframe | ||
|
|
||
| # flake8: noqa |
25 changes: 25 additions & 0 deletions
25
nisystemlink/clients/testmonitor/utilities/_dataframe_utilities.py
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,25 @@ | ||
| from typing import List | ||
|
|
||
| import pandas as pd | ||
| from nisystemlink.clients.testmonitor.models import Result | ||
|
|
||
|
|
||
| def convert_results_to_dataframe(results: List[Result]) -> pd.DataFrame: | ||
| """Normalizes the results into a Pandas DataFrame. | ||
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Args: | ||
| results: The list of results to normalize. | ||
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Returns: | ||
| A Pandas DataFrame with the normalized queried results. | ||
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| status_type_summary will be normalized into the respective status types. | ||
| For example, status_type_summary.LOOPING, status_type_summary.PASSED. | ||
| Status is normalized into status.status_type and status.status_name. | ||
| Properties are normalized into respective properties. For example, | ||
| properties.property1, properties.property2 and etc. | ||
| """ | ||
| results_dict = [result.dict(exclude_unset=True) for result in results] | ||
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| normalized_dataframe = pd.json_normalize(results_dict, sep=".") | ||
| normalized_dataframe.dropna(axis="columns", how="all", inplace=True) | ||
|
|
||
| return normalized_dataframe | ||
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
| # flake8: noqa |
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 @@ | ||
| # flake8: noqa |
65 changes: 65 additions & 0 deletions
65
tests/unit/testmonitor/test_testmonitor_dataframe_utilities.py
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,65 @@ | ||
| import uuid | ||
| from typing import List | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
| from nisystemlink.clients.testmonitor.models._result import Result | ||
| from nisystemlink.clients.testmonitor.models._status import Status, StatusType | ||
| from nisystemlink.clients.testmonitor.utilities._dataframe_utilities import ( | ||
| convert_results_to_dataframe, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def results() -> List[Result]: | ||
| """Sample results for testing purposes.""" | ||
| results = [ | ||
| Result( | ||
| status = Status.PASSED(), | ||
| started_at = "2018-05-07T18:58:05.219692Z", | ||
| updated_at = "2018-05-07T18:58:05.219692Z", | ||
| program_name = "My Program Name", | ||
| id = uuid.uuid1().hex, | ||
| system_id = uuid.uuid1().hex, | ||
| host_name = "host name", | ||
| part_number = uuid.uuid1().hex, | ||
| serial_number = uuid.uuid1().hex, | ||
| total_time_in_seconds = 16.76845106446358, | ||
| keywords = ["keyword1", "keyword2"], | ||
| properties = {"property1": "value1", "property2": "value2"}, | ||
| operator = "sample operator", | ||
| file_ids = [uuid.uuid1().hex, uuid.uuid1().hex], | ||
| data_table_ids = [uuid.uuid1().hex, uuid.uuid1().hex], | ||
| status_type_summary = {StatusType.PASSED: 1, StatusType.FAILED: 0}, | ||
| workspace = uuid.uuid1().hex, | ||
| ), | ||
| ] | ||
|
|
||
| return results | ||
|
|
||
|
|
||
| @pytest.mark.enterprise | ||
| class TestTestmonitorDataframeUtilities: | ||
| def test__convert_results_to_dataframe__returns_results_dataframe(self, results): | ||
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| expected_results_dict = [] | ||
| for result in results: | ||
| expected_results_dict.append(result.dict(exclude_unset=True)) | ||
| expected_results_dataframe = pd.json_normalize(expected_results_dict, sep=".") | ||
priyadarshini-ni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| expected_results_dataframe.dropna(axis="columns", how="all", inplace=True) | ||
|
|
||
| results_dataframe = convert_results_to_dataframe(results=results) | ||
|
|
||
| assert not results_dataframe.empty | ||
| assert isinstance(results_dataframe, pd.DataFrame) | ||
| assert len(results_dataframe) == 1 | ||
| assert len(results_dataframe.columns.tolist()) == 19 | ||
| assert results_dataframe.equals(expected_results_dataframe), expected_results_dataframe | ||
| pd.testing.assert_frame_equal(results_dataframe, expected_results_dataframe, check_dtype=True), expected_results_dataframe | ||
|
|
||
| def test__convert_results_to_dataframe_with_no_results__returns_empty_dataframe( | ||
| self, | ||
| ): | ||
| results_dataframe = convert_results_to_dataframe(results=[]) | ||
|
|
||
| assert isinstance(results_dataframe, pd.DataFrame) | ||
| assert results_dataframe.empty | ||
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.
Uh oh!
There was an error while loading. Please reload this page.