Skip to content
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

Specify columns when reading files with DocumentDataset #311

Merged
merged 4 commits into from
Oct 22, 2024

Conversation

sarahyurick
Copy link
Collaborator

Closes #180.

All of these will now work:

(1) Pandas and cuDF read_json do not support a columns parameter, so we read in the entire DataFrame and then remove unwanted columns behind the scenes.

dataset = DocumentDataset.read_json(dataset_path, columns=["col1", "col2"])

(2) Pandas and cuDF read_parquet both support a columns parameter, so we are able to take advantage of this functionality.

dataset = DocumentDataset.read_parquet(dataset_path, columns=["col1", "col2"])

(3) Pandas read_pickle (there is no cuDF read_pickle) does not support a columns parameter, so we read in the entire DataFrame and then remove unwanted columns behind the scenes.

dataset = DocumentDataset.read_pickle(dataset_path, columns=["col1", "col2"])

(4) Following cudf.read_json, you can specify dtype and prune_columns=True to only return the columns mentioned in the dtype argument. Note that Pandas does not support prune_columns.

dataset = DocumentDataset.read_json(
    dataset_path,
    dtype={"col1": str, "col2": str},
    prune_columns=True,
    backend="cudf",
)

Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>
Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>
Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>
Copy link
Collaborator

@ryantwolf ryantwolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing, then we should be good.

nemo_curator/utils/distributed_utils.py Show resolved Hide resolved
Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>
Copy link
Collaborator

@ryantwolf ryantwolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good with me, thanks!

@sarahyurick sarahyurick merged commit dc87963 into NVIDIA:main Oct 22, 2024
3 checks passed
@sarahyurick sarahyurick deleted the read_columns branch October 25, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Allow specify fields when reading files with DocumentDataset.
3 participants