Skip to content

Commit 9cf115f

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into ref-libreduction-5
2 parents 283f58d + 6c3c695 commit 9cf115f

File tree

19 files changed

+159
-115
lines changed

19 files changed

+159
-115
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,3 @@ repos:
3030
- id: isort
3131
language: python_venv
3232
exclude: ^pandas/__init__\.py$|^pandas/core/api\.py$
33-
- repo: https://github.com/pre-commit/mirrors-mypy
34-
rev: v0.730
35-
hooks:
36-
- id: mypy
37-
args:
38-
# As long as a some files are excluded from check-untyped-defs
39-
# we have to exclude it from the pre-commit hook as the configuration
40-
# is based on modules but the hook runs on files.
41-
- --no-check-untyped-defs
42-
- --follow-imports
43-
- skip
44-
files: pandas/

doc/source/whatsnew/v1.1.2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Bug fixes
3131
- Bug in :class:`Series` constructor raising a ``TypeError`` when constructing sparse datetime64 dtypes (:issue:`35762`)
3232
- Bug in :meth:`DataFrame.apply` with ``result_type="reduce"`` returning with incorrect index (:issue:`35683`)
3333
- Bug in :meth:`DateTimeIndex.format` and :meth:`PeriodIndex.format` with ``name=True`` setting the first item to ``"None"`` where it should bw ``""`` (:issue:`35712`)
34-
-
34+
- Bug in :meth:`Float64Index.__contains__` incorrectly raising ``TypeError`` instead of returning ``False`` (:issue:`35788`)
3535

3636
.. ---------------------------------------------------------------------------
3737

pandas/_libs/index.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ cdef class IndexEngine:
8080
values = self._get_index_values()
8181

8282
self._check_type(val)
83-
loc = _bin_search(values, val) # .searchsorted(val, side='left')
83+
try:
84+
loc = _bin_search(values, val) # .searchsorted(val, side='left')
85+
except TypeError:
86+
# GH#35788 e.g. val=None with float64 values
87+
raise KeyError(val)
8488
if loc >= len(values):
8589
raise KeyError(val)
8690
if values[loc] != val:

pandas/_libs/interval.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,6 @@ cdef class Interval(IntervalMixin):
291291
True
292292
>>> year_2017.length
293293
Timedelta('365 days 00:00:00')
294-
295-
And also you can create string intervals
296-
297-
>>> volume_1 = pd.Interval('Ant', 'Dog', closed='both')
298-
>>> 'Bee' in volume_1
299-
True
300294
"""
301295
_typ = "interval"
302296
__array_priority__ = 1000

pandas/core/indexes/multi.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from pandas._libs import algos as libalgos, index as libindex, lib
2121
from pandas._libs.hashtable import duplicated_int64
22-
from pandas._typing import AnyArrayLike, Scalar
22+
from pandas._typing import AnyArrayLike, Label, Scalar
2323
from pandas.compat.numpy import function as nv
2424
from pandas.errors import InvalidIndexError, PerformanceWarning, UnsortedIndexError
2525
from pandas.util._decorators import Appender, cache_readonly, doc
@@ -449,7 +449,12 @@ def from_arrays(cls, arrays, sortorder=None, names=lib.no_default) -> "MultiInde
449449
)
450450

451451
@classmethod
452-
def from_tuples(cls, tuples, sortorder=None, names=None):
452+
def from_tuples(
453+
cls,
454+
tuples,
455+
sortorder: Optional[int] = None,
456+
names: Optional[Sequence[Label]] = None,
457+
):
453458
"""
454459
Convert list of tuples to MultiIndex.
455460
@@ -490,6 +495,7 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
490495
elif is_iterator(tuples):
491496
tuples = list(tuples)
492497

498+
arrays: List[Sequence[Label]]
493499
if len(tuples) == 0:
494500
if names is None:
495501
raise TypeError("Cannot infer number of levels from empty list")
@@ -700,8 +706,13 @@ def levels(self):
700706
return FrozenList(result)
701707

702708
def _set_levels(
703-
self, levels, level=None, copy=False, validate=True, verify_integrity=False
704-
):
709+
self,
710+
levels,
711+
level=None,
712+
copy: bool = False,
713+
validate: bool = True,
714+
verify_integrity: bool = False,
715+
) -> None:
705716
# This is NOT part of the levels property because it should be
706717
# externally not allowed to set levels. User beware if you change
707718
# _levels directly
@@ -719,10 +730,10 @@ def _set_levels(
719730
)
720731
else:
721732
level_numbers = [self._get_level_number(lev) for lev in level]
722-
new_levels = list(self._levels)
733+
new_levels_list = list(self._levels)
723734
for lev_num, lev in zip(level_numbers, levels):
724-
new_levels[lev_num] = ensure_index(lev, copy=copy)._shallow_copy()
725-
new_levels = FrozenList(new_levels)
735+
new_levels_list[lev_num] = ensure_index(lev, copy=copy)._shallow_copy()
736+
new_levels = FrozenList(new_levels_list)
726737

727738
if verify_integrity:
728739
new_codes = self._verify_integrity(levels=new_levels)
@@ -875,8 +886,13 @@ def codes(self):
875886
return self._codes
876887

877888
def _set_codes(
878-
self, codes, level=None, copy=False, validate=True, verify_integrity=False
879-
):
889+
self,
890+
codes,
891+
level=None,
892+
copy: bool = False,
893+
validate: bool = True,
894+
verify_integrity: bool = False,
895+
) -> None:
880896
if validate:
881897
if level is None and len(codes) != self.nlevels:
882898
raise ValueError("Length of codes must match number of levels")
@@ -890,11 +906,13 @@ def _set_codes(
890906
)
891907
else:
892908
level_numbers = [self._get_level_number(lev) for lev in level]
893-
new_codes = list(self._codes)
909+
new_codes_list = list(self._codes)
894910
for lev_num, level_codes in zip(level_numbers, codes):
895911
lev = self.levels[lev_num]
896-
new_codes[lev_num] = _coerce_indexer_frozen(level_codes, lev, copy=copy)
897-
new_codes = FrozenList(new_codes)
912+
new_codes_list[lev_num] = _coerce_indexer_frozen(
913+
level_codes, lev, copy=copy
914+
)
915+
new_codes = FrozenList(new_codes_list)
898916

899917
if verify_integrity:
900918
new_codes = self._verify_integrity(codes=new_codes)
@@ -2435,7 +2453,7 @@ def _get_partial_string_timestamp_match_key(self, key):
24352453
if isinstance(key, str) and self.levels[0]._supports_partial_string_indexing:
24362454
# Convert key '2016-01-01' to
24372455
# ('2016-01-01'[, slice(None, None, None)]+)
2438-
key = tuple([key] + [slice(None)] * (len(self.levels) - 1))
2456+
key = (key,) + (slice(None),) * (len(self.levels) - 1)
24392457

24402458
if isinstance(key, tuple):
24412459
# Convert (..., '2016-01-01', ...) in tuple to
@@ -3086,7 +3104,7 @@ def _update_indexer(idxr, indexer=indexer):
30863104
elif is_list_like(k):
30873105
# a collection of labels to include from this level (these
30883106
# are or'd)
3089-
indexers = None
3107+
indexers: Optional[Int64Index] = None
30903108
for x in k:
30913109
try:
30923110
idxrs = _convert_to_indexer(

pandas/io/excel/_xlwt.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from typing import TYPE_CHECKING, Dict
2+
13
import pandas._libs.json as json
24

35
from pandas.io.excel._base import ExcelWriter
46
from pandas.io.excel._util import _validate_freeze_panes
57

8+
if TYPE_CHECKING:
9+
from xlwt import XFStyle
10+
611

712
class _XlwtWriter(ExcelWriter):
813
engine = "xlwt"
@@ -29,12 +34,11 @@ def save(self):
2934
"""
3035
Save workbook to disk.
3136
"""
32-
return self.book.save(self.path)
37+
self.book.save(self.path)
3338

3439
def write_cells(
3540
self, cells, sheet_name=None, startrow=0, startcol=0, freeze_panes=None
3641
):
37-
# Write the frame cells using xlwt.
3842

3943
sheet_name = self._get_sheet_name(sheet_name)
4044

@@ -49,7 +53,7 @@ def write_cells(
4953
wks.set_horz_split_pos(freeze_panes[0])
5054
wks.set_vert_split_pos(freeze_panes[1])
5155

52-
style_dict = {}
56+
style_dict: Dict[str, XFStyle] = {}
5357

5458
for cell in cells:
5559
val, fmt = self._value_with_fmt(cell.val)
@@ -101,14 +105,14 @@ def _style_to_xlwt(
101105
f"{key}: {cls._style_to_xlwt(value, False)}"
102106
for key, value in item.items()
103107
]
104-
out = f"{(line_sep).join(it)} "
108+
out = f"{line_sep.join(it)} "
105109
return out
106110
else:
107111
it = [
108112
f"{key} {cls._style_to_xlwt(value, False)}"
109113
for key, value in item.items()
110114
]
111-
out = f"{(field_sep).join(it)} "
115+
out = f"{field_sep.join(it)} "
112116
return out
113117
else:
114118
item = f"{item}"

pandas/io/parquet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def write(
128128
self.api.parquet.write_table(table, path, compression=compression, **kwargs)
129129

130130
def read(
131-
self, path, columns=None, storage_options: StorageOptions = None, **kwargs,
131+
self, path, columns=None, storage_options: StorageOptions = None, **kwargs
132132
):
133133
if is_fsspec_url(path) and "filesystem" not in kwargs:
134134
import_optional_dependency("fsspec")
@@ -218,7 +218,7 @@ def write(
218218
)
219219

220220
def read(
221-
self, path, columns=None, storage_options: StorageOptions = None, **kwargs,
221+
self, path, columns=None, storage_options: StorageOptions = None, **kwargs
222222
):
223223
if is_fsspec_url(path):
224224
fsspec = import_optional_dependency("fsspec")

pandas/io/parsers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,10 +1967,6 @@ def _do_date_conversions(self, names, data):
19671967

19681968

19691969
class CParserWrapper(ParserBase):
1970-
"""
1971-
1972-
"""
1973-
19741970
def __init__(self, src, **kwds):
19751971
self.kwds = kwds
19761972
kwds = kwds.copy()

pandas/io/pytables.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,7 +2931,7 @@ def read_index_node(
29312931
# If the index was an empty array write_array_empty() will
29322932
# have written a sentinel. Here we replace it with the original.
29332933
if "shape" in node._v_attrs and np.prod(node._v_attrs.shape) == 0:
2934-
data = np.empty(node._v_attrs.shape, dtype=node._v_attrs.value_type,)
2934+
data = np.empty(node._v_attrs.shape, dtype=node._v_attrs.value_type)
29352935
kind = _ensure_decoded(node._v_attrs.kind)
29362936
name = None
29372937

@@ -4103,7 +4103,7 @@ def create_description(
41034103
return d
41044104

41054105
def read_coordinates(
4106-
self, where=None, start: Optional[int] = None, stop: Optional[int] = None,
4106+
self, where=None, start: Optional[int] = None, stop: Optional[int] = None
41074107
):
41084108
"""
41094109
select coordinates (row numbers) from a table; return the
@@ -4374,7 +4374,7 @@ def write_data_chunk(
43744374
self.table.flush()
43754375

43764376
def delete(
4377-
self, where=None, start: Optional[int] = None, stop: Optional[int] = None,
4377+
self, where=None, start: Optional[int] = None, stop: Optional[int] = None
43784378
):
43794379

43804380
# delete all rows (and return the nrows)
@@ -4805,7 +4805,7 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
48054805
if inferred_type == "date":
48064806
converted = np.asarray([v.toordinal() for v in values], dtype=np.int32)
48074807
return IndexCol(
4808-
name, converted, "date", _tables().Time32Col(), index_name=index_name,
4808+
name, converted, "date", _tables().Time32Col(), index_name=index_name
48094809
)
48104810
elif inferred_type == "string":
48114811

@@ -4821,13 +4821,13 @@ def _convert_index(name: str, index: Index, encoding: str, errors: str) -> Index
48214821

48224822
elif inferred_type in ["integer", "floating"]:
48234823
return IndexCol(
4824-
name, values=converted, kind=kind, typ=atom, index_name=index_name,
4824+
name, values=converted, kind=kind, typ=atom, index_name=index_name
48254825
)
48264826
else:
48274827
assert isinstance(converted, np.ndarray) and converted.dtype == object
48284828
assert kind == "object", kind
48294829
atom = _tables().ObjectAtom()
4830-
return IndexCol(name, converted, kind, atom, index_name=index_name,)
4830+
return IndexCol(name, converted, kind, atom, index_name=index_name)
48314831

48324832

48334833
def _unconvert_index(

pandas/plotting/_matplotlib/boxplot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import namedtuple
2+
from typing import TYPE_CHECKING
23
import warnings
34

45
from matplotlib.artist import setp
@@ -14,6 +15,9 @@
1415
from pandas.plotting._matplotlib.style import _get_standard_colors
1516
from pandas.plotting._matplotlib.tools import _flatten, _subplots
1617

18+
if TYPE_CHECKING:
19+
from matplotlib.axes import Axes
20+
1721

1822
class BoxPlot(LinePlot):
1923
_kind = "box"
@@ -150,7 +154,7 @@ def _make_plot(self):
150154
labels = [pprint_thing(key) for key in range(len(labels))]
151155
self._set_ticklabels(ax, labels)
152156

153-
def _set_ticklabels(self, ax, labels):
157+
def _set_ticklabels(self, ax: "Axes", labels):
154158
if self.orientation == "vertical":
155159
ax.set_xticklabels(labels)
156160
else:
@@ -292,7 +296,7 @@ def maybe_color_bp(bp, **kwds):
292296
if not kwds.get("capprops"):
293297
setp(bp["caps"], color=colors[3], alpha=1)
294298

295-
def plot_group(keys, values, ax):
299+
def plot_group(keys, values, ax: "Axes"):
296300
keys = [pprint_thing(x) for x in keys]
297301
values = [np.asarray(remove_na_arraylike(v), dtype=object) for v in values]
298302
bp = ax.boxplot(values, **kwds)

0 commit comments

Comments
 (0)