-
Notifications
You must be signed in to change notification settings - Fork 26
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
Load subset into dataframe #54
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1221e0d
Combine subsets into single dataframe
GeorgesLorre 4d98a56
Add first test + fixtures
GeorgesLorre 46f1cd2
Revamp dataset tests
GeorgesLorre a688793
Rebase
GeorgesLorre 129b603
Re-enable column renaming based on subset
GeorgesLorre 4342575
Re-enable column renaming based on subset
GeorgesLorre 1f8cfca
Re-enable column renaming based on subset
GeorgesLorre 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 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 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 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,21 @@ | ||
name: Test component 1 | ||
description: This is an example component | ||
image: example_component:latest | ||
|
||
input_subsets: | ||
properties: | ||
fields: | ||
Name: | ||
type: "utf8" | ||
HP: | ||
type: "int32" | ||
types: | ||
fields: | ||
Type 1: | ||
type: "utf8" | ||
Type 2: | ||
type: "utf8" | ||
args: | ||
storage_args: | ||
description: Storage arguments | ||
type: str |
This file contains 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,34 @@ | ||
{ | ||
"metadata": { | ||
"base_path": "tests/example_data/subsets", | ||
"run_id": "12345", | ||
"component_id": "67890" | ||
}, | ||
"index": { | ||
"location": "/index" | ||
}, | ||
"subsets": { | ||
"properties": { | ||
"location": "/properties", | ||
"fields": { | ||
"Name": { | ||
"type": "utf8" | ||
}, | ||
"HP": { | ||
"type": "int32" | ||
} | ||
} | ||
}, | ||
"types": { | ||
"location": "/types", | ||
"fields": { | ||
"Type 1": { | ||
"type": "utf8" | ||
}, | ||
"Type 2": { | ||
"type": "utf8" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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,39 @@ | ||
""" | ||
This is a small script to split the raw data into different subsets to be used while testing. | ||
|
||
The data is the 151 first pokemon and the following fields are available: | ||
|
||
'id', 'Name', 'Type 1', 'Type 2', 'Total', 'HP', 'Attack', 'Defense', | ||
'Sp. Atk', 'Sp. Def', 'Speed', 'source', 'Legendary' | ||
|
||
|
||
""" | ||
from pathlib import Path | ||
import dask.dataframe as dd | ||
|
||
data_path = Path(__file__).parent | ||
output_path = Path(__file__).parent.parent / "subsets/" | ||
|
||
|
||
def split_into_subsets(): | ||
# read in complete dataset | ||
master_df = dd.read_parquet(path=data_path / "testset.parquet") | ||
|
||
# create index subset | ||
index_df = master_df[["id", "source"]] | ||
index_df.set_index("id") | ||
index_df.to_parquet(output_path / "index") | ||
|
||
# create properties subset | ||
properies_df = master_df[["id", "source", "Name", "HP"]] | ||
properies_df.set_index("id") | ||
properies_df.to_parquet(output_path / "properties") | ||
|
||
# create types subset | ||
types_df = master_df[["id", "source", "Type 1", "Type 2"]] | ||
types_df.set_index("id") | ||
types_df.to_parquet(output_path / "types") | ||
|
||
|
||
if __name__ == "__main__": | ||
split_into_subsets() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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,40 @@ | ||
import json | ||
import pytest | ||
import dask.dataframe as dd | ||
from pathlib import Path | ||
|
||
from fondant.manifest import Manifest | ||
from fondant.dataset import FondantDataset | ||
from fondant.component_spec import FondantComponentSpec | ||
|
||
manifest_path = Path(__file__).parent / "example_data/manifest.json" | ||
component_spec_path = Path(__file__).parent / "example_data/components/1.yaml" | ||
|
||
|
||
@pytest.fixture | ||
def manifest(): | ||
return Manifest.from_file(manifest_path) | ||
|
||
|
||
@pytest.fixture | ||
def component_spec(): | ||
return FondantComponentSpec.from_file(component_spec_path) | ||
|
||
|
||
def test_load_index(manifest): | ||
fds = FondantDataset(manifest) | ||
assert len(fds._load_index()) == 151 | ||
|
||
|
||
def test_merge_subsets(manifest, component_spec): | ||
fds = FondantDataset(manifest=manifest) | ||
df = fds.load_dataframe(spec=component_spec) | ||
assert len(df) == 151 | ||
assert list(df.columns) == [ | ||
"id", | ||
"source", | ||
"properties_Name", | ||
"properties_HP", | ||
"types_Type 1", | ||
"types_Type 2", | ||
] |
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.
Nit: can we move this up from the optional to the required dependencies?