Skip to content

Commit 0a083c8

Browse files
Merge branch 'main' into pandas-vs-scipy-interpolation-naming-clarification
2 parents d1ce4ca + 2e55bff commit 0a083c8

File tree

9 files changed

+21
-44
lines changed

9 files changed

+21
-44
lines changed

pandas/_testing/asserters.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,12 @@ def raise_assert_detail(
571571

572572
if isinstance(left, np.ndarray):
573573
left = pprint_thing(left)
574-
elif (
575-
isinstance(left, CategoricalDtype)
576-
or isinstance(left, PandasDtype)
577-
or isinstance(left, StringDtype)
578-
):
574+
elif isinstance(left, (CategoricalDtype, PandasDtype, StringDtype)):
579575
left = repr(left)
580576

581577
if isinstance(right, np.ndarray):
582578
right = pprint_thing(right)
583-
elif (
584-
isinstance(right, CategoricalDtype)
585-
or isinstance(right, PandasDtype)
586-
or isinstance(right, StringDtype)
587-
):
579+
elif isinstance(right, (CategoricalDtype, PandasDtype, StringDtype)):
588580
right = repr(right)
589581

590582
msg += f"""

pandas/core/arrays/datetimelike.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@
112112
)
113113

114114
from pandas.core import (
115+
algorithms,
115116
nanops,
116117
ops,
117118
)
118119
from pandas.core.algorithms import (
119120
checked_add_with_arr,
120121
isin,
121-
mode,
122122
unique1d,
123123
)
124124
from pandas.core.arraylike import OpsMixin
@@ -1690,7 +1690,7 @@ def _mode(self, dropna: bool = True):
16901690
if dropna:
16911691
mask = self.isna()
16921692

1693-
i8modes = mode(self.view("i8"), mask=mask)
1693+
i8modes = algorithms.mode(self.view("i8"), mask=mask)
16941694
npmodes = i8modes.view(self._ndarray.dtype)
16951695
npmodes = cast(np.ndarray, npmodes)
16961696
return self._from_backing_data(npmodes)

pandas/core/base.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@
6161
ops,
6262
)
6363
from pandas.core.accessor import DirNamesMixin
64-
from pandas.core.algorithms import (
65-
duplicated,
66-
unique1d,
67-
value_counts,
68-
)
6964
from pandas.core.arraylike import OpsMixin
7065
from pandas.core.arrays import ExtensionArray
7166
from pandas.core.construction import (
@@ -991,7 +986,7 @@ def value_counts(
991986
NaN 1
992987
dtype: int64
993988
"""
994-
return value_counts(
989+
return algorithms.value_counts(
995990
self,
996991
sort=sort,
997992
ascending=ascending,
@@ -1006,7 +1001,7 @@ def unique(self):
10061001
# i.e. ExtensionArray
10071002
result = values.unique()
10081003
else:
1009-
result = unique1d(values)
1004+
result = algorithms.unique1d(values)
10101005
return result
10111006

10121007
@final
@@ -1294,7 +1289,7 @@ def drop_duplicates(self, *, keep: DropKeep = "first"):
12941289

12951290
@final
12961291
def _duplicated(self, keep: DropKeep = "first") -> npt.NDArray[np.bool_]:
1297-
return duplicated(self._values, keep=keep)
1292+
return algorithms.duplicated(self._values, keep=keep)
12981293

12991294
def _arith_method(self, other, op):
13001295
res_name = ops.get_op_result_name(self, other)

pandas/core/computation/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def maybe_expression(s) -> bool:
650650
"""loose checking if s is a pytables-acceptable expression"""
651651
if not isinstance(s, str):
652652
return False
653-
ops = PyTablesExprVisitor.binary_ops + PyTablesExprVisitor.unary_ops + ("=",)
653+
operations = PyTablesExprVisitor.binary_ops + PyTablesExprVisitor.unary_ops + ("=",)
654654

655655
# make sure we have an op at least
656-
return any(op in s for op in ops)
656+
return any(op in s for op in operations)

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ def _get_default_index_names(
16481648
from pandas.core.indexes.multi import MultiIndex
16491649

16501650
if names is not None:
1651-
if isinstance(names, str) or isinstance(names, int):
1651+
if isinstance(names, (int, str)):
16521652
names = [names]
16531653

16541654
if not isinstance(names, list) and names is not None:

pandas/core/indexes/datetimes.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from __future__ import annotations
22

3-
from datetime import (
4-
date,
5-
datetime,
6-
time,
7-
timedelta,
8-
tzinfo,
9-
)
3+
import datetime as dt
104
import operator
115
from typing import (
126
TYPE_CHECKING,
@@ -257,7 +251,7 @@ def _engine_type(self) -> type[libindex.DatetimeEngine]:
257251

258252
_data: DatetimeArray
259253
inferred_freq: str | None
260-
tz: tzinfo | None
254+
tz: dt.tzinfo | None
261255

262256
# --------------------------------------------------------------------
263257
# methods that dispatch to DatetimeArray and wrap result
@@ -514,7 +508,7 @@ def snap(self, freq: Frequency = "S") -> DatetimeIndex:
514508
# --------------------------------------------------------------------
515509
# Indexing Methods
516510

517-
def _parsed_string_to_bounds(self, reso: Resolution, parsed: datetime):
511+
def _parsed_string_to_bounds(self, reso: Resolution, parsed: dt.datetime):
518512
"""
519513
Calculate datetime bounds for parsed time string and its resolution.
520514
@@ -604,13 +598,13 @@ def get_loc(self, key, method=None, tolerance=None):
604598

605599
key = self._maybe_cast_for_get_loc(key)
606600

607-
elif isinstance(key, timedelta):
601+
elif isinstance(key, dt.timedelta):
608602
# GH#20464
609603
raise TypeError(
610604
f"Cannot index {type(self).__name__} with {type(key).__name__}"
611605
)
612606

613-
elif isinstance(key, time):
607+
elif isinstance(key, dt.time):
614608
if method is not None:
615609
raise NotImplementedError(
616610
"cannot yet lookup inexact labels when key is a time object"
@@ -648,7 +642,7 @@ def _maybe_cast_for_get_loc(self, key) -> Timestamp:
648642
def _maybe_cast_slice_bound(self, label, side: str):
649643

650644
# GH#42855 handle date here instead of get_slice_bound
651-
if isinstance(label, date) and not isinstance(label, datetime):
645+
if isinstance(label, dt.date) and not isinstance(label, dt.datetime):
652646
# Pandas supports slicing with dates, treated as datetimes at midnight.
653647
# https://github.com/pandas-dev/pandas/issues/31501
654648
label = Timestamp(label).to_pydatetime()
@@ -674,12 +668,12 @@ def slice_indexer(self, start=None, end=None, step=None):
674668
# For historical reasons DatetimeIndex supports slices between two
675669
# instances of datetime.time as if it were applying a slice mask to
676670
# an array of (self.hour, self.minute, self.seconds, self.microsecond).
677-
if isinstance(start, time) and isinstance(end, time):
671+
if isinstance(start, dt.time) and isinstance(end, dt.time):
678672
if step is not None and step != 1:
679673
raise ValueError("Must have step size of 1 with time slices")
680674
return self.indexer_between_time(start, end)
681675

682-
if isinstance(start, time) or isinstance(end, time):
676+
if isinstance(start, dt.time) or isinstance(end, dt.time):
683677
raise KeyError("Cannot mix time and non-time slice keys")
684678

685679
def check_str_or_none(point) -> bool:
@@ -1092,6 +1086,6 @@ def bdate_range(
10921086
)
10931087

10941088

1095-
def _time_to_micros(time_obj: time) -> int:
1089+
def _time_to_micros(time_obj: dt.time) -> int:
10961090
seconds = time_obj.hour * 60 * 60 + 60 * time_obj.minute + time_obj.second
10971091
return 1_000_000 * seconds + time_obj.microsecond

pandas/io/formats/xml.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,12 @@ def add_declaration(self) -> bytes:
419419
"""
420420
decl = f'<?xml version="1.0" encoding="{self.encoding}"?>\n'
421421

422-
doc = (
422+
return (
423423
self.out_xml
424424
if self.out_xml.startswith(b"<?xml")
425425
else decl.encode(self.encoding) + self.out_xml
426426
)
427427

428-
return doc
429-
430428
def remove_declaration(self) -> bytes:
431429
"""
432430
Remove xml declaration.

pandas/io/json/_table_schema.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)
1313
import warnings
1414

15-
from pandas._libs import json
15+
from pandas._libs.json import loads
1616
from pandas._typing import (
1717
DtypeObj,
1818
JSONSerializable,
@@ -41,7 +41,6 @@
4141
from pandas import Series
4242
from pandas.core.indexes.multi import MultiIndex
4343

44-
loads = json.loads
4544

4645
TABLE_SCHEMA_VERSION = "1.4.0"
4746

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ disable = [
101101

102102
# pylint type "R": refactor, for bad code smell
103103
"comparison-with-itself",
104-
"consider-merging-isinstance",
105104
"consider-using-ternary",
106105
"consider-using-with",
107106
"cyclic-import",

0 commit comments

Comments
 (0)