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

Reset index before returning dataframe #805

Merged
merged 3 commits into from
Feb 11, 2025
Merged

Reset index before returning dataframe #805

merged 3 commits into from
Feb 11, 2025

Conversation

ccl-core
Copy link
Contributor

@ccl-core ccl-core commented Feb 11, 2025

Sometimes, when processing parquet-based datasets using pandas, the index column is treated as the dataframe's index, even though it should be another column. This results in an error at the column lookup step in the ReadFields operation:

Example dataset where this happens: https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia

@ccl-core ccl-core requested a review from a team as a code owner February 11, 2025 14:33
Copy link

github-actions bot commented Feb 11, 2025

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@@ -110,7 +110,9 @@ def _read_file_content(self, encoding_format: str, file: Path) -> pd.DataFrame:
return pd.read_json(file, lines=True)
elif encoding_format == EncodingFormat.PARQUET:
try:
return pd.read_parquet(file)
df = pd.read_parquet(file)
df.reset_index(inplace=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Either:

df.reset_index(inplace=True)

or

df = df.reset_index()

because we use this style a lot

@@ -110,7 +110,9 @@ def _read_file_content(self, encoding_format: str, file: Path) -> pd.DataFrame:
return pd.read_json(file, lines=True)
elif encoding_format == EncodingFormat.PARQUET:
try:
return pd.read_parquet(file)
df = pd.read_parquet(file)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can add a comment saying something like: Sometimes the author already set an index in Parquet, so we want to reset it to always have the same format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks! Also updated the PR description with more context.

Copy link
Contributor

@marcenacp marcenacp left a comment

Choose a reason for hiding this comment

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

Thanks!

@ccl-core ccl-core merged commit 5f71dbe into main Feb 11, 2025
11 of 12 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants