Skip to content

Commit 33b7ec8

Browse files
Removed doc decorator from masked.py and replaced with hard coded doc strings
1 parent 46ed6b1 commit 33b7ec8

File tree

1 file changed

+252
-8
lines changed

1 file changed

+252
-8
lines changed

pandas/core/arrays/masked.py

Lines changed: 252 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,15 @@ def _cast_pointwise_result(self, values) -> ArrayLike:
169169
return result
170170

171171
@classmethod
172-
@doc(ExtensionArray._empty)
173172
def _empty(cls, shape: Shape, dtype: ExtensionDtype) -> Self:
173+
"""
174+
Create an ExtensionArray with the given shape and dtype.
175+
176+
See also
177+
--------
178+
ExtensionDtype.empty
179+
ExtensionDtype.empty is the 'official' public version of this API.
180+
"""
174181
dtype = cast(BaseMaskedDtype, dtype)
175182
values: np.ndarray = np.empty(shape, dtype=dtype.type)
176183
values.fill(dtype._internal_fill_value)
@@ -252,8 +259,44 @@ def _pad_or_backfill(
252259
new_values = self
253260
return new_values
254261

255-
@doc(ExtensionArray.fillna)
256262
def fillna(self, value, limit: int | None = None, copy: bool = True) -> Self:
263+
"""
264+
Fill NA/NaN values using the specified method.
265+
266+
Parameters
267+
----------
268+
value : scalar, array-like
269+
If a scalar value is passed it is used to fill all missing values.
270+
Alternatively, an array-like "value" can be given. It's expected
271+
that the array-like have the same length as 'self'.
272+
limit : int, default None
273+
The maximum number of entries where NA values will be filled.
274+
copy : bool, default True
275+
Whether to make a copy of the data before filling. If False, then
276+
the original should be modified and no new memory should be allocated.
277+
For ExtensionArray subclasses that cannot do this, it is at the
278+
author's discretion whether to ignore "copy=False" or to raise.
279+
280+
Returns
281+
-------
282+
ExtensionArray
283+
With NA/NaN filled.
284+
285+
See Also
286+
--------
287+
api.extensions.ExtensionArray.dropna : Return ExtensionArray without
288+
NA values.
289+
api.extensions.ExtensionArray.isna : A 1-D array indicating if
290+
each value is missing.
291+
292+
Examples
293+
--------
294+
>>> arr = pd.array([np.nan, np.nan, 2, 3, np.nan, np.nan])
295+
>>> arr.fillna(0)
296+
<IntegerArray>
297+
[0, 0, 2, 3, 0, 0]
298+
Length: 6, dtype: Int64
299+
"""
257300
mask = self._mask
258301
if limit is not None and limit < len(self):
259302
modify = mask.cumsum() > limit
@@ -548,8 +591,30 @@ def to_numpy(
548591
data = self._data.astype(dtype, copy=copy)
549592
return data
550593

551-
@doc(ExtensionArray.tolist)
552594
def tolist(self) -> list:
595+
"""
596+
Return a list of the values.
597+
598+
These are each a scalar type, which is a Python scalar
599+
(for str, int, float) or a pandas scalar
600+
(for Timestamp/Timedelta/Interval/Period)
601+
602+
Returns
603+
-------
604+
list
605+
Python list of values in array.
606+
607+
See Also
608+
--------
609+
Index.to_list: Return a list of the values in the Index.
610+
Series.to_list: Return a list of the values in the Series.
611+
612+
Examples
613+
--------
614+
>>> arr = pd.array([1, 2, 3])
615+
>>> arr.tolist()
616+
[1, 2, 3]
617+
"""
553618
if self.ndim > 1:
554619
return [x.tolist() for x in self]
555620
dtype = None if self._hasna else self._data.dtype
@@ -1075,10 +1140,37 @@ def _rank(
10751140

10761141
return FloatingArray(result, mask=mask)
10771142

1078-
@doc(ExtensionArray.duplicated)
10791143
def duplicated(
10801144
self, keep: Literal["first", "last", False] = "first"
10811145
) -> npt.NDArray[np.bool_]:
1146+
"""
1147+
Return boolean ndarray denoting duplicate values.
1148+
1149+
Parameters
1150+
----------
1151+
keep : {'first', 'last', False}, default 'first'
1152+
- ``first`` : Mark duplicates as ``True`` except for the first occurrence.
1153+
- ``last`` : Mark duplicates as ``True`` except for the last occurrence.
1154+
- False : Mark all duplicates as ``True``.
1155+
1156+
Returns
1157+
-------
1158+
ndarray[bool]
1159+
With true in indices where elements are duplicated and false otherwise.
1160+
1161+
See Also
1162+
--------
1163+
DataFrame.duplicated : Return boolean Series denoting
1164+
duplicate rows.
1165+
Series.duplicated : Indicate duplicate Series values.
1166+
api.extensions.ExtensionArray.unique : Compute the ExtensionArray
1167+
of unique values.
1168+
1169+
Examples
1170+
--------
1171+
>>> pd.array([1, 1, 2, 3, 3], dtype="Int64").duplicated()
1172+
array([False, True, False, False, True])
1173+
"""
10821174
values = self._data
10831175
mask = self._mask
10841176
return algos.duplicated(values, keep=keep, mask=mask)
@@ -1094,13 +1186,56 @@ def unique(self) -> Self:
10941186
uniques, mask = algos.unique_with_mask(self._data, self._mask)
10951187
return self._simple_new(uniques, mask)
10961188

1097-
@doc(ExtensionArray.searchsorted)
10981189
def searchsorted(
10991190
self,
11001191
value: NumpyValueArrayLike | ExtensionArray,
11011192
side: Literal["left", "right"] = "left",
11021193
sorter: NumpySorter | None = None,
11031194
) -> npt.NDArray[np.intp] | np.intp:
1195+
"""
1196+
Find indices where elements should be inserted to maintain order.
1197+
1198+
Find the indices into a sorted array `self` (a) such that, if the
1199+
corresponding elements in `value` were inserted before the indices,
1200+
the order of `self` would be preserved.
1201+
1202+
Assuming that `self` is sorted:
1203+
1204+
====== ================================
1205+
`side` returned index `i` satisfies
1206+
====== ================================
1207+
left ``self[i-1] < value <= self[i]``
1208+
right ``self[i-1] <= value < self[i]``
1209+
====== ================================
1210+
1211+
Parameters
1212+
----------
1213+
value : array-like, list or scalar
1214+
Value(s) to insert into `self`.
1215+
side : {'left', 'right'}, optional
1216+
If 'left', the index of the first suitable location found is given.
1217+
If 'right', return the last such index. If there is no suitable
1218+
index, return either 0 or N (where N is the length of `self`).
1219+
sorter : 1-D array-like, optional
1220+
Optional array of integer indices that sort array a into ascending
1221+
order. They are typically the result of argsort.
1222+
1223+
Returns
1224+
-------
1225+
array of ints or int
1226+
If value is array-like, array of insertion points.
1227+
If value is scalar, a single integer.
1228+
1229+
See Also
1230+
--------
1231+
numpy.searchsorted : Similar method from NumPy.
1232+
1233+
Examples
1234+
--------
1235+
>>> arr = pd.array([1, 2, 3, 5])
1236+
>>> arr.searchsorted([4])
1237+
array([3])
1238+
"""
11041239
if self._hasna:
11051240
raise ValueError(
11061241
"searchsorted requires array to be sorted, which is impossible "
@@ -1111,11 +1246,56 @@ def searchsorted(
11111246
# Base class searchsorted would cast to object, which is *much* slower.
11121247
return self._data.searchsorted(value, side=side, sorter=sorter)
11131248

1114-
@doc(ExtensionArray.factorize)
11151249
def factorize(
11161250
self,
11171251
use_na_sentinel: bool = True,
11181252
) -> tuple[np.ndarray, ExtensionArray]:
1253+
"""
1254+
Encode the extension array as an enumerated type.
1255+
1256+
Parameters
1257+
----------
1258+
use_na_sentinel : bool, default True
1259+
If True, the sentinel -1 will be used for NaN values. If False,
1260+
NaN values will be encoded as non-negative integers and will not drop the
1261+
NaN from the uniques of the values.
1262+
1263+
.. versionadded:: 1.5.0
1264+
1265+
Returns
1266+
-------
1267+
codes : ndarray
1268+
An integer NumPy array that's an indexer into the original
1269+
ExtensionArray.
1270+
uniques : ExtensionArray
1271+
An ExtensionArray containing the unique values of `self`.
1272+
1273+
.. note::
1274+
1275+
uniques will *not* contain an entry for the NA value of
1276+
the ExtensionArray if there are any missing values present
1277+
in `self`.
1278+
1279+
See Also
1280+
--------
1281+
factorize : Top-level factorize method that dispatches here.
1282+
1283+
Notes
1284+
-----
1285+
:meth:`pandas.factorize` offers a `sort` keyword as well.
1286+
1287+
Examples
1288+
--------
1289+
>>> idx1 = pd.PeriodIndex(
1290+
... ["2014-01", "2014-01", "2014-02", "2014-02", "2014-03", "2014-03"],
1291+
... freq="M",
1292+
... )
1293+
>>> arr, idx = idx1.factorize()
1294+
>>> arr
1295+
array([0, 0, 1, 1, 2, 2])
1296+
>>> idx
1297+
PeriodIndex(['2014-01', '2014-02', '2014-03'], dtype='period[M]')
1298+
"""
11191299
arr = self._data
11201300
mask = self._mask
11211301

@@ -1148,8 +1328,38 @@ def factorize(
11481328

11491329
return codes, uniques_ea
11501330

1151-
@doc(ExtensionArray._values_for_argsort)
11521331
def _values_for_argsort(self) -> np.ndarray:
1332+
"""
1333+
Return values for sorting.
1334+
1335+
Returns
1336+
-------
1337+
ndarray
1338+
The transformed values should maintain the ordering between values
1339+
within the array.
1340+
1341+
See Also
1342+
--------
1343+
ExtensionArray.argsort : Return the indices that would sort this array.
1344+
1345+
Notes
1346+
-----
1347+
The caller is responsible for *not* modifying these values in-place, so
1348+
it is safe for implementers to give views on ``self``.
1349+
1350+
Functions that use this (e.g. ``ExtensionArray.argsort``) should ignore
1351+
entries with missing values in the original array (according to
1352+
``self.isna()``). This means that the corresponding entries in the returned
1353+
array don't need to be modified to sort correctly.
1354+
1355+
Examples
1356+
--------
1357+
In most cases, this is the underlying Numpy array of the ``ExtensionArray``:
1358+
1359+
>>> arr = pd.array([1, 2, 3])
1360+
>>> arr._values_for_argsort()
1361+
array([1, 2, 3])
1362+
"""
11531363
return self._data
11541364

11551365
def value_counts(self, dropna: bool = True) -> Series:
@@ -1198,8 +1408,42 @@ def _mode(self, dropna: bool = True) -> Self:
11981408
result = type(self)(result, res_mask)
11991409
return result[result.argsort()]
12001410

1201-
@doc(ExtensionArray.equals)
12021411
def equals(self, other) -> bool:
1412+
"""
1413+
Return if another array is equivalent to this array.
1414+
1415+
Equivalent means that both arrays have the same shape and dtype, and
1416+
all values compare equal. Missing values in the same location are
1417+
considered equal (in contrast with normal equality).
1418+
1419+
Parameters
1420+
----------
1421+
other : ExtensionArray
1422+
Array to compare to this Array.
1423+
1424+
Returns
1425+
-------
1426+
boolean
1427+
Whether the arrays are equivalent.
1428+
1429+
See Also
1430+
--------
1431+
numpy.array_equal : Equivalent method for numpy array.
1432+
Series.equals : Equivalent method for Series.
1433+
DataFrame.equals : Equivalent method for DataFrame.
1434+
1435+
Examples
1436+
--------
1437+
>>> arr1 = pd.array([1, 2, np.nan])
1438+
>>> arr2 = pd.array([1, 2, np.nan])
1439+
>>> arr1.equals(arr2)
1440+
True
1441+
1442+
>>> arr1 = pd.array([1, 3, np.nan])
1443+
>>> arr2 = pd.array([1, 2, np.nan])
1444+
>>> arr1.equals(arr2)
1445+
False
1446+
"""
12031447
if type(self) != type(other):
12041448
return False
12051449
if other.dtype != self.dtype:

0 commit comments

Comments
 (0)