Skip to content

Commit 6a18b99

Browse files
committed
Merge branch 'main' into 37715-remove-mypy-ignore-VI
2 parents 3c50078 + 073156e commit 6a18b99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+218
-220
lines changed

asv_bench/benchmarks/pandas_vb_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
try:
1818
import pandas._testing as tm
1919
except ImportError:
20-
import pandas.util.testing as tm # noqa:F401
20+
import pandas.util.testing as tm # noqa: F401
2121

2222

2323
numeric_dtypes = [

doc/source/user_guide/window.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ be calculated with :meth:`~Rolling.apply` by specifying a separate column of wei
9696
return arr
9797
9898
df = pd.DataFrame([[1, 2, 0.6], [2, 3, 0.4], [3, 4, 0.2], [4, 5, 0.7]])
99-
df.rolling(2, method="table", min_periods=0).apply(weighted_mean, raw=True, engine="numba") # noqa:E501
99+
df.rolling(2, method="table", min_periods=0).apply(weighted_mean, raw=True, engine="numba") # noqa: E501
100100
101101
.. versionadded:: 1.3
102102

pandas/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
try:
2222
# numpy compat
2323
from pandas.compat import (
24-
is_numpy_dev as _is_numpy_dev, # pyright: ignore # noqa:F401
24+
is_numpy_dev as _is_numpy_dev, # pyright: ignore[reportUnusedImport] # noqa: F401,E501
2525
)
2626
except ImportError as _err: # pragma: no cover
2727
_module = _err.name
@@ -41,7 +41,7 @@
4141
)
4242

4343
# let init-time option registration happen
44-
import pandas.core.config_init # pyright: ignore # noqa:F401
44+
import pandas.core.config_init # pyright: ignore[reportUnusedImport] # noqa: F401
4545

4646
from pandas.core.api import (
4747
# dtype

pandas/_config/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"using_copy_on_write",
1818
]
1919
from pandas._config import config
20-
from pandas._config import dates # pyright: ignore # noqa:F401
20+
from pandas._config import dates # pyright: ignore[reportUnusedImport] # noqa: F401
2121
from pandas._config.config import (
2222
_global_config,
2323
describe_option,

pandas/_libs/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# Below imports needs to happen first to ensure pandas top level
1414
# module gets monkeypatched with the pandas_datetime_CAPI
1515
# see pandas_datetime_exec in pd_datetime.c
16-
import pandas._libs.pandas_parser # noqa # isort: skip # type: ignore[reportUnusedImport]
17-
import pandas._libs.pandas_datetime # noqa # isort: skip # type: ignore[reportUnusedImport]
16+
import pandas._libs.pandas_parser # noqa: F401,E501 # isort: skip # type: ignore[reportUnusedImport]
17+
import pandas._libs.pandas_datetime # noqa: F401,E501 # isort: skip # type: ignore[reportUnusedImport]
1818
from pandas._libs.interval import Interval
1919
from pandas._libs.tslibs import (
2020
NaT,

pandas/_libs/lib.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from enum import Enum
3030
class _NoDefault(Enum):
3131
no_default = ...
3232

33-
no_default: Final = _NoDefault.no_default # noqa
33+
no_default: Final = _NoDefault.no_default # noqa: PYI015
3434
NoDefault = Literal[_NoDefault.no_default]
3535

3636
i8max: int

pandas/core/arrays/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def _box_func(self, x: np.datetime64) -> Timestamp | NaTType:
534534
# error: Return type "Union[dtype, DatetimeTZDtype]" of "dtype"
535535
# incompatible with return type "ExtensionDtype" in supertype
536536
# "ExtensionArray"
537-
def dtype(self) -> np.dtype[np.datetime64] | DatetimeTZDtype: # type: ignore[override] # noqa:E501
537+
def dtype(self) -> np.dtype[np.datetime64] | DatetimeTZDtype: # type: ignore[override] # noqa: E501
538538
"""
539539
The dtype for the DatetimeArray.
540540

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ def _ensure_nanosecond_dtype(dtype: DtypeObj) -> None:
12001200
Traceback (most recent call last):
12011201
...
12021202
TypeError: dtype=timedelta64[ps] is not supported. Supported resolutions are 's', 'ms', 'us', and 'ns'
1203-
""" # noqa:E501
1203+
""" # noqa: E501
12041204
msg = (
12051205
f"The '{dtype.name}' dtype has no unit. "
12061206
f"Please pass in '{dtype.name}[ns]' instead."

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
902902
# error: Incompatible types in assignment (expression has type
903903
# "Dict[int, PandasExtensionDtype]", base class "PandasExtensionDtype"
904904
# defined the type as "Dict[str, PandasExtensionDtype]") [assignment]
905-
_cache_dtypes: dict[BaseOffset, PeriodDtype] = {} # type: ignore[assignment] # noqa:E501
905+
_cache_dtypes: dict[BaseOffset, PeriodDtype] = {} # type: ignore[assignment] # noqa: E501
906906
__hash__ = PeriodDtypeBase.__hash__
907907
_freq: BaseOffset
908908

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10431,7 +10431,7 @@ def corr(
1043110431
dogs cats
1043210432
dogs 1.0 NaN
1043310433
cats NaN 1.0
10434-
""" # noqa:E501
10434+
""" # noqa: E501
1043510435
data = self._get_numeric_data() if numeric_only else self
1043610436
cols = data.columns
1043710437
idx = cols.copy()
@@ -10676,7 +10676,7 @@ def corrwith(
1067610676
d 1.0
1067710677
e NaN
1067810678
dtype: float64
10679-
""" # noqa:E501
10679+
""" # noqa: E501
1068010680
axis = self._get_axis_number(axis)
1068110681
this = self._get_numeric_data() if numeric_only else self
1068210682

pandas/core/generic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
_shared_doc_kwargs = {
211211
"axes": "keywords for axes",
212212
"klass": "Series/DataFrame",
213-
"axes_single_arg": "{0 or 'index'} for Series, {0 or 'index', 1 or 'columns'} for DataFrame", # noqa:E501
213+
"axes_single_arg": "{0 or 'index'} for Series, {0 or 'index', 1 or 'columns'} for DataFrame", # noqa: E501
214214
"inplace": """
215215
inplace : bool, default False
216216
If True, performs operation inplace and returns None.""",
@@ -2904,7 +2904,7 @@ def to_sql(
29042904
>>> with engine.connect() as conn:
29052905
... conn.execute(text("SELECT * FROM integers")).fetchall()
29062906
[(1,), (None,), (2,)]
2907-
""" # noqa:E501
2907+
""" # noqa: E501
29082908
from pandas.io import sql
29092909

29102910
return sql.to_sql(
@@ -5901,7 +5901,7 @@ def sample(
59015901
num_legs num_wings num_specimen_seen
59025902
falcon 2 2 10
59035903
fish 0 0 8
5904-
""" # noqa:E501
5904+
""" # noqa: E501
59055905
if axis is None:
59065906
axis = 0
59075907

pandas/core/groupby/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4227,7 +4227,7 @@ def sample(
42274227
5 black 5
42284228
2 blue 2
42294229
0 red 0
4230-
""" # noqa:E501
4230+
""" # noqa: E501
42314231
if self._selected_obj.empty:
42324232
# GH48459 prevent ValueError when object is empty
42334233
return self._selected_obj

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ def delete(self, loc) -> list[Block]:
15371537
else:
15381538
# No overload variant of "__getitem__" of "ExtensionArray" matches
15391539
# argument type "Tuple[slice, slice]"
1540-
values = self.values[previous_loc + 1 : idx, :] # type: ignore[call-overload] # noqa
1540+
values = self.values[previous_loc + 1 : idx, :] # type: ignore[call-overload] # noqa: E501
15411541
locs = mgr_locs_arr[previous_loc + 1 : idx]
15421542
nb = type(self)(
15431543
values, placement=BlockPlacement(locs), ndim=self.ndim, refs=refs

pandas/core/methods/describe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _select_data(self) -> DataFrame:
193193
include=self.include,
194194
exclude=self.exclude,
195195
)
196-
return data # pyright: ignore
196+
return data # pyright: ignore[reportGeneralTypeIssues]
197197

198198

199199
def reorder_columns(ldesc: Sequence[Series]) -> list[Hashable]:

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ def corr(
26822682
>>> s2 = pd.Series([.3, .6, .0, .1])
26832683
>>> s1.corr(s2, method=histogram_intersection)
26842684
0.3
2685-
""" # noqa:E501
2685+
""" # noqa: E501
26862686
this, other = self.align(other, join="inner", copy=False)
26872687
if len(this) == 0:
26882688
return np.nan

pandas/core/tools/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def to_numeric(
218218
values = ensure_object(values)
219219
coerce_numeric = errors not in ("ignore", "raise")
220220
try:
221-
values, new_mask = lib.maybe_convert_numeric( # type: ignore[call-overload] # noqa
221+
values, new_mask = lib.maybe_convert_numeric( # type: ignore[call-overload] # noqa: E501
222222
values,
223223
set(),
224224
coerce_numeric=coerce_numeric,

pandas/io/parquet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __init__(self) -> None:
161161
import pyarrow.parquet
162162

163163
# import utils to register the pyarrow extension types
164-
import pandas.core.arrays.arrow.extension_types # pyright: ignore # noqa:F401
164+
import pandas.core.arrays.arrow.extension_types # pyright: ignore[reportUnusedImport] # noqa: F401,E501
165165

166166
self.api = pyarrow
167167

@@ -243,7 +243,7 @@ def read(
243243
mapping = _arrow_dtype_mapping()
244244
to_pandas_kwargs["types_mapper"] = mapping.get
245245
elif dtype_backend == "pyarrow":
246-
to_pandas_kwargs["types_mapper"] = pd.ArrowDtype # type: ignore[assignment] # noqa
246+
to_pandas_kwargs["types_mapper"] = pd.ArrowDtype # type: ignore[assignment] # noqa: E501
247247

248248
manager = get_option("mode.data_manager")
249249
if manager == "array":

pandas/io/parsers/base_parser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def _infer_types(
713713
values,
714714
na_values,
715715
False,
716-
convert_to_masked_nullable=non_default_dtype_backend, # type: ignore[arg-type] # noqa
716+
convert_to_masked_nullable=non_default_dtype_backend, # type: ignore[arg-type] # noqa: E501
717717
)
718718
except (ValueError, TypeError):
719719
# e.g. encountering datetime string gets ValueError
@@ -749,7 +749,7 @@ def _infer_types(
749749
np.asarray(values),
750750
true_values=self.true_values,
751751
false_values=self.false_values,
752-
convert_to_masked_nullable=non_default_dtype_backend, # type: ignore[arg-type] # noqa
752+
convert_to_masked_nullable=non_default_dtype_backend, # type: ignore[arg-type] # noqa: E501
753753
)
754754
if result.dtype == np.bool_ and non_default_dtype_backend:
755755
if bool_mask is None:
@@ -812,7 +812,7 @@ def _cast_types(self, values: ArrayLike, cast_type: DtypeObj, column) -> ArrayLi
812812
if is_bool_dtype(cast_type):
813813
# error: Unexpected keyword argument "true_values" for
814814
# "_from_sequence_of_strings" of "ExtensionArray"
815-
return array_type._from_sequence_of_strings( # type: ignore[call-arg] # noqa:E501
815+
return array_type._from_sequence_of_strings( # type: ignore[call-arg] # noqa: E501
816816
values,
817817
dtype=cast_type,
818818
true_values=self.true_values,

pandas/io/parsers/python_parser.py

+32-22
Original file line numberDiff line numberDiff line change
@@ -365,25 +365,34 @@ def _convert_data(
365365
clean_dtypes,
366366
)
367367

368+
@cache_readonly
369+
def _have_mi_columns(self) -> bool:
370+
if self.header is None:
371+
return False
372+
373+
header = self.header
374+
if isinstance(header, (list, tuple, np.ndarray)):
375+
return len(header) > 1
376+
else:
377+
return False
378+
368379
def _infer_columns(
369380
self,
370381
) -> tuple[list[list[Scalar | None]], int, set[Scalar | None]]:
371382
names = self.names
372383
num_original_columns = 0
373384
clear_buffer = True
374385
unnamed_cols: set[Scalar | None] = set()
375-
self._header_line = None
376386

377387
if self.header is not None:
378388
header = self.header
389+
have_mi_columns = self._have_mi_columns
379390

380391
if isinstance(header, (list, tuple, np.ndarray)):
381-
have_mi_columns = len(header) > 1
382392
# we have a mi columns, so read an extra line
383393
if have_mi_columns:
384394
header = list(header) + [header[-1] + 1]
385395
else:
386-
have_mi_columns = False
387396
header = [header]
388397

389398
columns: list[list[Scalar | None]] = []
@@ -531,27 +540,14 @@ def _infer_columns(
531540
columns, columns[0], num_original_columns
532541
)
533542
else:
534-
try:
535-
line = self._buffered_line()
536-
537-
except StopIteration as err:
538-
if not names:
539-
raise EmptyDataError("No columns to parse from file") from err
540-
541-
line = names[:]
542-
543-
# Store line, otherwise it is lost for guessing the index
544-
self._header_line = line
545-
ncols = len(line)
543+
ncols = len(self._header_line)
546544
num_original_columns = ncols
547545

548546
if not names:
549547
columns = [list(range(ncols))]
550-
columns = self._handle_usecols(
551-
columns, columns[0], num_original_columns
552-
)
553-
elif self.usecols is None or len(names) >= num_original_columns:
554-
columns = self._handle_usecols([names], names, num_original_columns)
548+
columns = self._handle_usecols(columns, columns[0], ncols)
549+
elif self.usecols is None or len(names) >= ncols:
550+
columns = self._handle_usecols([names], names, ncols)
555551
num_original_columns = len(names)
556552
elif not callable(self.usecols) and len(names) != len(self.usecols):
557553
raise ValueError(
@@ -560,12 +556,26 @@ def _infer_columns(
560556
)
561557
else:
562558
# Ignore output but set used columns.
563-
self._handle_usecols([names], names, ncols)
564559
columns = [names]
565-
num_original_columns = ncols
560+
self._handle_usecols(columns, columns[0], ncols)
566561

567562
return columns, num_original_columns, unnamed_cols
568563

564+
@cache_readonly
565+
def _header_line(self):
566+
# Store line for reuse in _get_index_name
567+
if self.header is not None:
568+
return None
569+
570+
try:
571+
line = self._buffered_line()
572+
except StopIteration as err:
573+
if not self.names:
574+
raise EmptyDataError("No columns to parse from file") from err
575+
576+
line = self.names[:]
577+
return line
578+
569579
def _handle_usecols(
570580
self,
571581
columns: list[list[Scalar | None]],

pandas/io/sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def to_sql(
758758
rows as stipulated in the
759759
`sqlite3 <https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.rowcount>`__ or
760760
`SQLAlchemy <https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.BaseCursorResult.rowcount>`__
761-
""" # noqa:E501
761+
""" # noqa: E501
762762
if if_exists not in ("fail", "replace", "append"):
763763
raise ValueError(f"'{if_exists}' is not valid for if_exists")
764764

0 commit comments

Comments
 (0)