Skip to content

Commit f6a2330

Browse files
committed
doctest fixups
1 parent 9c2f5ac commit f6a2330

File tree

17 files changed

+66
-52
lines changed

17 files changed

+66
-52
lines changed

asv_bench/benchmarks/indexing_engines.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ class NumericEngineIndexing:
6767
def setup(self, engine_and_dtype, index_type, unique, N):
6868
engine, dtype = engine_and_dtype
6969

70-
if index_type == "non_monotonic" and dtype in ["int16", "int8", "uint8"]:
70+
if (
71+
index_type == "non_monotonic"
72+
and dtype in [np.int16, np.int8, np.uint8]
73+
and unique
74+
):
7175
# Values overflow
7276
raise NotImplementedError
7377

@@ -119,6 +123,14 @@ def setup(self, engine_and_dtype, index_type, unique, N):
119123
engine, dtype = engine_and_dtype
120124
dtype = dtype.lower()
121125

126+
if (
127+
index_type == "non_monotonic"
128+
and dtype in ["int16", "int8", "uint8"]
129+
and unique
130+
):
131+
# Values overflow
132+
raise NotImplementedError
133+
122134
if index_type == "monotonic_incr":
123135
if unique:
124136
arr = np.arange(N * 3, dtype=dtype)

pandas/core/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
351351
AttributeError: The series must contain integer data only.
352352
>>> df = pd.Series([1, 2, 3])
353353
>>> df.int_accessor.sum()
354-
6"""
354+
np.int64(6)"""
355355

356356

357357
@doc(_register_accessor, klass="Series", examples=_register_series_examples)

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def unique(values):
415415
416416
>>> pd.unique(pd.array([1 + 1j, 2, 3]))
417417
<NumpyExtensionArray>
418-
[(1+1j), (2+0j), (3+0j)]
418+
[np.complex128(1+1j), np.complex128(2+0j), np.complex128(3+0j)]
419419
Length: 3, dtype: complex128
420420
"""
421421
return unique_with_mask(values)

pandas/core/arrays/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ def interpolate(
10721072
... limit_area="inside",
10731073
... )
10741074
<NumpyExtensionArray>
1075-
[0.0, 1.0, 2.0, 3.0]
1075+
[np.float64(0.0), np.float64(1.0), np.float64(2.0), np.float64(3.0)]
10761076
Length: 4, dtype: float64
10771077
10781078
Interpolating values in a FloatingArray:
@@ -1962,7 +1962,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]:
19621962
... return lambda x: "*" + str(x) + "*" if boxed else repr(x) + "*"
19631963
>>> MyExtensionArray(np.array([1, 2, 3, 4]))
19641964
<MyExtensionArray>
1965-
[1*, 2*, 3*, 4*]
1965+
[np.int64(1)*, np.int64(2)*, np.int64(3)*, np.int64(4)*]
19661966
Length: 4, dtype: int64
19671967
"""
19681968
if boxed:
@@ -2176,11 +2176,11 @@ def _reduce(
21762176
Examples
21772177
--------
21782178
>>> pd.array([1, 2, 3])._reduce("min")
2179-
1
2179+
np.int64(1)
21802180
>>> pd.array([1, 2, 3])._reduce("max")
2181-
3
2181+
np.int64(3)
21822182
>>> pd.array([1, 2, 3])._reduce("sum")
2183-
6
2183+
np.int64(6)
21842184
>>> pd.array([1, 2, 3])._reduce("mean")
21852185
2.0
21862186
>>> pd.array([1, 2, 3])._reduce("median")

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _unbox_scalar(
275275
--------
276276
>>> arr = pd.array(np.array(["1970-01-01"], "datetime64[ns]"))
277277
>>> arr._unbox_scalar(arr[0])
278-
numpy.datetime64('1970-01-01T00:00:00.000000000')
278+
np.datetime64('1970-01-01T00:00:00.000000000')
279279
"""
280280
raise AbstractMethodError(self)
281281

pandas/core/arrays/interval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,8 @@ def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
17751775
[(0, 1], (1, 2]]
17761776
Length: 2, dtype: interval[int64, right]
17771777
>>> idx.to_tuples()
1778-
array([(0, 1), (1, 2)], dtype=object)
1778+
array([(np.int64(0), np.int64(1)), (np.int64(1), np.int64(2))],
1779+
dtype=object)
17791780
17801781
For :class:`pandas.IntervalIndex`:
17811782

pandas/core/arrays/masked.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,17 +1470,17 @@ def all(
14701470
skips NAs):
14711471
14721472
>>> pd.array([True, True, pd.NA]).all()
1473-
True
1473+
np.True_
14741474
>>> pd.array([1, 1, pd.NA]).all()
1475-
True
1475+
np.True_
14761476
>>> pd.array([True, False, pd.NA]).all()
1477-
False
1477+
np.False_
14781478
>>> pd.array([], dtype="boolean").all()
1479-
True
1479+
np.True_
14801480
>>> pd.array([pd.NA], dtype="boolean").all()
1481-
True
1481+
np.True_
14821482
>>> pd.array([pd.NA], dtype="Float64").all()
1483-
True
1483+
np.True_
14841484
14851485
With ``skipna=False``, the result can be NA if this is logically
14861486
required (whether ``pd.NA`` is True or False influences the result):

pandas/core/arrays/numpy_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class NumpyExtensionArray( # type: ignore[misc]
8080
--------
8181
>>> pd.arrays.NumpyExtensionArray(np.array([0, 1, 2, 3]))
8282
<NumpyExtensionArray>
83-
[0, 1, 2, 3]
83+
[np.int64(0), np.int64(1), np.int64(2), np.int64(3)]
8484
Length: 4, dtype: int64
8585
"""
8686

pandas/core/arrays/sparse/accessor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate):
297297
--------
298298
>>> df = pd.DataFrame({"a": [1, 2, 0, 0], "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
299299
>>> df.sparse.density
300-
0.5
300+
np.float64(0.5)
301301
"""
302302

303303
def _validate(self, data) -> None:
@@ -459,7 +459,7 @@ def density(self) -> float:
459459
--------
460460
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
461461
>>> df.sparse.density
462-
0.5
462+
np.float64(0.5)
463463
"""
464464
tmp = np.mean([column.array.density for _, column in self._parent.items()])
465465
return tmp

pandas/core/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def array(self) -> ExtensionArray:
558558
559559
>>> pd.Series([1, 2, 3]).array
560560
<NumpyExtensionArray>
561-
[1, 2, 3]
561+
[np.int64(1), np.int64(2), np.int64(3)]
562562
Length: 3, dtype: int64
563563
564564
For extension types, like Categorical, the actual ExtensionArray
@@ -804,9 +804,9 @@ def argmax(
804804
dtype: float64
805805
806806
>>> s.argmax()
807-
2
807+
np.int64(2)
808808
>>> s.argmin()
809-
0
809+
np.int64(0)
810810
811811
The maximum cereal calories is the third element and
812812
the minimum cereal calories is the first element,
@@ -1360,7 +1360,7 @@ def factorize(
13601360
dtype: int64
13611361
13621362
>>> ser.searchsorted(4)
1363-
3
1363+
np.int64(3)
13641364
13651365
>>> ser.searchsorted([0, 4])
13661366
array([0, 3])

0 commit comments

Comments
 (0)