fix: correct read_csv behaviours with use_cols, names, index_col#1804
Merged
chelsea-lin merged 4 commits intomainfrom Jun 12, 2025
Merged
fix: correct read_csv behaviours with use_cols, names, index_col#1804chelsea-lin merged 4 commits intomainfrom
chelsea-lin merged 4 commits intomainfrom
Conversation
sycai
reviewed
Jun 10, 2025
bigframes/session/loader.py
Outdated
Comment on lines
632
to
644
| table_column_names = [field.name for field in table.schema] | ||
| for column_name in columns: | ||
| if column_name not in table_column_names: | ||
| possibility = min( | ||
| table_column_names, | ||
| key=lambda item: bigframes._tools.strings.levenshtein_distance( | ||
| column_name, item | ||
| ), | ||
| ) | ||
| raise ValueError( | ||
| f"Column '{column_name}' of `columns` not found in this table. " | ||
| f"Did you mean '{possibility}'?" | ||
| ) |
Contributor
There was a problem hiding this comment.
nit: Shall we use a helper function/method? The indentation is very deep here. (https://goto.google.com/tott/733)
bigframes/session/loader.py
Outdated
Comment on lines
613
to
614
| else: | ||
| if names is not None: |
Contributor
There was a problem hiding this comment.
It feels like this is the same as elif names is not None: which can save you a level of indentation.
bigframes/session/loader.py
Outdated
Comment on lines
615
to
672
| assert len(table.schema) >= len(list(names)) | ||
| assert len(list(names)) >= len(columns) | ||
| table_column_names = [ | ||
| field.name for field in table.schema[: len(list(names))] | ||
| ] | ||
|
|
||
| invalid_columns = set(columns) - set(names) | ||
| if len(invalid_columns) != 0: | ||
| raise ValueError( | ||
| "Usecols do not match columns, columns expected but not " | ||
| f"found: {invalid_columns}" | ||
| ) | ||
|
|
||
| rename_to_schema = dict(zip(list(names), table_column_names)) | ||
| names = columns | ||
| columns = [rename_to_schema[renamed_name] for renamed_name in columns] |
Contributor
There was a problem hiding this comment.
The hosting function is very long. I think there might be an opportunity to make this code block a helper function/method
go/pystyle#function-length
Contributor
Author
There was a problem hiding this comment.
Refactored for more readable. Please check.
94c8af9 to
d345126
Compare
sycai
previously approved these changes
Jun 11, 2025
sycai
approved these changes
Jun 11, 2025
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.
Fixes internal issue 421466334 🦕