-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: read_csv not converting to float for python engine with decimal sep, usecols and parse_dates #38334
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
Merged
BUG: read_csv not converting to float for python engine with decimal sep, usecols and parse_dates #38334
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8c2e1ca
BUG: read_csv not converting to float for python engine with decimal …
phofl c1b9a7b
Move sorted
phofl 76b91bf
Fix mypy issues
phofl 9de5059
Run black
phofl ca76832
Merge branch 'master' of https://github.com/pandas-dev/pandas into 35873
phofl 85a3d22
Move whatsnew
phofl 2958d2a
Remove comment
phofl 1d740e0
Merge branch 'master' of https://github.com/pandas-dev/pandas into 35873
phofl 88bf395
Remove from 1.2
phofl 6ad5385
Merge branch 'master' into 35873
phofl da4b602
Merge branch 'master' into 35873
phofl 384c114
Move test
phofl 070f67d
Merge branch '35873' of https://github.com/phofl/pandas into 35873
phofl 70780da
Remove import
phofl 9d6205a
Merge branch 'master' of https://github.com/pandas-dev/pandas into 35873
phofl 4afa2c8
Always define self._col_indices
phofl 5bee24a
Move comments
phofl d96a256
Merge branch 'master' of https://github.com/pandas-dev/pandas into 35873
phofl c6a226b
Add init files
phofl 3ece01b
Fix line numbers
phofl 6cca960
Remove mypy ignores
phofl 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
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 |
---|---|---|
|
@@ -2293,7 +2293,7 @@ def __init__(self, f: Union[FilePathOrBuffer, List], **kwds): | |
|
||
# Get columns in two steps: infer from data, then | ||
# infer column indices from self.usecols if it is specified. | ||
self._col_indices = None | ||
self._col_indices: Optional[List[int]] = None | ||
try: | ||
( | ||
self.columns, | ||
|
@@ -2335,6 +2335,9 @@ def __init__(self, f: Union[FilePathOrBuffer, List], **kwds): | |
if self.index_names is None: | ||
self.index_names = index_names | ||
|
||
if self._col_indices is None: | ||
self._col_indices = list(range(len(self.columns))) | ||
|
||
self._validate_parse_dates_presence(self.columns) | ||
if self.parse_dates: | ||
self._no_thousands_columns = self._set_no_thousands_columns() | ||
|
@@ -2358,7 +2361,11 @@ def _set(x): | |
if is_integer(x): | ||
noconvert_columns.add(x) | ||
else: | ||
noconvert_columns.add(self.columns.index(x)) | ||
# pandas\io\parsers.py:2366: error: Unsupported right | ||
# operand type for in ("Optional[List[int]") [index] | ||
noconvert_columns.add( | ||
self._col_indices[self.columns.index(x)] # type: ignore[index] | ||
) | ||
|
||
if isinstance(self.parse_dates, list): | ||
for val in self.parse_dates: | ||
|
@@ -2700,7 +2707,6 @@ def _infer_columns(self): | |
# overwritten. | ||
self._handle_usecols(columns, names) | ||
else: | ||
self._col_indices = None | ||
num_original_columns = len(names) | ||
columns = [names] | ||
else: | ||
|
@@ -2782,7 +2788,7 @@ def _handle_usecols(self, columns, usecols_key): | |
[n for i, n in enumerate(column) if i in col_indices] | ||
for column in columns | ||
] | ||
self._col_indices = col_indices | ||
self._col_indices = sorted(col_indices) | ||
return columns | ||
|
||
def _buffered_line(self): | ||
|
@@ -3186,16 +3192,16 @@ def _rows_to_cols(self, content): | |
for i, a in enumerate(zipped_content) | ||
if ( | ||
i < len(self.index_col) | ||
# pandas\io\parsers.py:3159: error: Unsupported right | ||
# operand type for in ("Optional[Any]") [operator] | ||
# pandas\io\parsers.py:3198: error: Unsupported right | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
# operand type for in ("Optional[List[int]") [operator] | ||
or i - len(self.index_col) # type: ignore[operator] | ||
in self._col_indices | ||
) | ||
] | ||
else: | ||
zipped_content = [ | ||
# pandas\io\parsers.py:3164: error: Unsupported right | ||
# operand type for in ("Optional[Any]") [operator] | ||
# pandas\io\parsers.py:3207: error: Unsupported right | ||
# operand type for in ("Optional[List[int]") [operator] | ||
a | ||
for i, a in enumerate(zipped_content) | ||
if i in self._col_indices # type: ignore[operator] | ||
|
Empty file.
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
Empty file.
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.
you need to assert that the result values is not None (assign it to a new variable first).
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.
Thanks very much. That helped me a lot.