-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Fix mypy ignores in parsers #39342
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e2875e8
TYP: Fix mypy ignores in parsers
phofl 02d729e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
phofl f22e3d6
Use new annotations
phofl d008e2d
Fix annotations
phofl 1bd6ae5
Merge branch 'master' of https://github.com/pandas-dev/pandas into ty…
phofl e442d61
Roll back type annotations
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
from collections import defaultdict | ||
import csv | ||
import datetime | ||
import itertools | ||
from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, Union, cast | ||
from typing import ( | ||
Any, | ||
DefaultDict, | ||
Dict, | ||
Iterable, | ||
List, | ||
Optional, | ||
Sequence, | ||
Set, | ||
Union, | ||
cast, | ||
) | ||
import warnings | ||
|
||
import numpy as np | ||
|
@@ -335,9 +348,7 @@ def _maybe_dedup_names(self, names): | |
# would be nice! | ||
if self.mangle_dupe_cols: | ||
names = list(names) # so we can index | ||
# pandas\io\parsers.py:1559: error: Need type annotation for | ||
# 'counts' [var-annotated] | ||
counts = defaultdict(int) # type: ignore[var-annotated] | ||
counts: DefaultDict[int | str, int] = defaultdict(int) | ||
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. if an mi, the dict key is a tuple? |
||
is_potential_mi = _is_potential_multi_index(names, self.index_col) | ||
|
||
for i, col in enumerate(names): | ||
|
@@ -382,9 +393,8 @@ def _make_index(self, data, alldata, columns, indexnamerow=False): | |
# add names for the index | ||
if indexnamerow: | ||
coffset = len(indexnamerow) - len(columns) | ||
# pandas\io\parsers.py:1604: error: Item "None" of "Optional[Any]" | ||
# has no attribute "set_names" [union-attr] | ||
index = index.set_names(indexnamerow[:coffset]) # type: ignore[union-attr] | ||
assert index is not None | ||
index = index.set_names(indexnamerow[:coffset]) | ||
|
||
# maybe create a mi on the columns | ||
columns = self._maybe_make_multi_index_columns(columns, self.col_names) | ||
|
@@ -458,9 +468,8 @@ def _agg_index(self, index, try_parse_dates=True) -> Index: | |
col_na_fvalues = set() | ||
|
||
if isinstance(self.na_values, dict): | ||
# pandas\io\parsers.py:1678: error: Value of type | ||
# "Optional[Any]" is not indexable [index] | ||
col_name = self.index_names[i] # type: ignore[index] | ||
assert self.index_names is not None | ||
col_name = self.index_names[i] | ||
if col_name is not None: | ||
col_na_values, col_na_fvalues = _get_na_values( | ||
col_name, self.na_values, self.na_fvalues, self.keep_default_na | ||
|
@@ -549,7 +558,7 @@ def _convert_to_ndarrays( | |
return result | ||
|
||
def _set_noconvert_dtype_columns( | ||
self, col_indices: List[int], names: List[Union[int, str]] | ||
self, col_indices: List[int], names: List[int | str] | ||
) -> Set[int]: | ||
""" | ||
Set the columns that should not undergo dtype conversions. | ||
|
@@ -568,7 +577,7 @@ def _set_noconvert_dtype_columns( | |
------- | ||
A set of integers containing the positions of the columns not to convert. | ||
""" | ||
usecols: Optional[Union[List[int], List[str]]] | ||
usecols: List[int] | List[str] | None | ||
noconvert_columns = set() | ||
if self.usecols_dtype == "integer": | ||
# A set of integers will be converted to a list in | ||
|
@@ -850,7 +859,7 @@ def _clean_index_names(self, columns, index_col, unnamed_cols): | |
return [None] * len(index_col), columns, index_col | ||
|
||
cp_cols = list(columns) | ||
index_names = [] | ||
index_names: List[int | str | None] = [] | ||
|
||
# don't mutate | ||
index_col = list(index_col) | ||
|
@@ -871,10 +880,7 @@ def _clean_index_names(self, columns, index_col, unnamed_cols): | |
# Only clean index names that were placeholders. | ||
for i, name in enumerate(index_names): | ||
if isinstance(name, str) and name in unnamed_cols: | ||
# pandas\io\parsers.py:3445: error: No overload variant of | ||
# "__setitem__" of "list" matches argument types "int", "None" | ||
# [call-overload] | ||
index_names[i] = None # type: ignore[call-overload] | ||
index_names[i] = None | ||
|
||
return index_names, columns, index_col | ||
|
||
|
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
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
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.
if an mi, the dict key is a tuple?
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 are right, thx. I looked them through again and fixed 2 more I think