Skip to content

Commit ce8af21

Browse files
authored
REF: docstrings that dont need to go into shared_docs (pandas-dev#31408)
1 parent 8a33050 commit ce8af21

File tree

9 files changed

+85
-167
lines changed

9 files changed

+85
-167
lines changed

pandas/core/indexes/base.py

+42-114
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,8 @@ def _get_attributes_dict(self):
505505
"""
506506
return {k: getattr(self, k, None) for k in self._attributes}
507507

508-
_index_shared_docs[
509-
"_shallow_copy"
510-
] = """
508+
def _shallow_copy(self, values=None, **kwargs):
509+
"""
511510
Create a new Index with the same class as the caller, don't copy the
512511
data, use the same object attributes with passed in attributes taking
513512
precedence.
@@ -519,9 +518,6 @@ def _get_attributes_dict(self):
519518
values : the values to create the new Index, optional
520519
kwargs : updates the default attributes for this Index
521520
"""
522-
523-
@Appender(_index_shared_docs["_shallow_copy"])
524-
def _shallow_copy(self, values=None, **kwargs):
525521
if values is None:
526522
values = self.values
527523

@@ -659,9 +655,8 @@ def view(self, cls=None):
659655
result._id = self._id
660656
return result
661657

662-
_index_shared_docs[
663-
"astype"
664-
] = """
658+
def astype(self, dtype, copy=True):
659+
"""
665660
Create an Index with values cast to dtypes. The class of a new Index
666661
is determined by dtype. When conversion is impossible, a ValueError
667662
exception is raised.
@@ -683,9 +678,6 @@ def view(self, cls=None):
683678
Index
684679
Index with values cast to specified dtype.
685680
"""
686-
687-
@Appender(_index_shared_docs["astype"])
688-
def astype(self, dtype, copy=True):
689681
if is_dtype_equal(self.dtype, dtype):
690682
return self.copy() if copy else self
691683

@@ -823,9 +815,8 @@ def repeat(self, repeats, axis=None):
823815
# --------------------------------------------------------------------
824816
# Copying Methods
825817

826-
_index_shared_docs[
827-
"copy"
828-
] = """
818+
def copy(self, name=None, deep=False, dtype=None, **kwargs):
819+
"""
829820
Make a copy of this object. Name and dtype sets those attributes on
830821
the new object.
831822
@@ -844,9 +835,6 @@ def repeat(self, repeats, axis=None):
844835
In most cases, there should be no functional difference from using
845836
``deep``, but if ``deep`` is passed it will attempt to deepcopy.
846837
"""
847-
848-
@Appender(_index_shared_docs["copy"])
849-
def copy(self, name=None, deep=False, dtype=None, **kwargs):
850838
if deep:
851839
new_index = self._shallow_copy(self._data.copy())
852840
else:
@@ -1537,9 +1525,8 @@ def droplevel(self, level=0):
15371525
verify_integrity=False,
15381526
)
15391527

1540-
_index_shared_docs[
1541-
"_get_grouper_for_level"
1542-
] = """
1528+
def _get_grouper_for_level(self, mapper, level=None):
1529+
"""
15431530
Get index grouper corresponding to an index level
15441531
15451532
Parameters
@@ -1558,9 +1545,6 @@ def droplevel(self, level=0):
15581545
uniques : Index or None
15591546
Index of unique values for level.
15601547
"""
1561-
1562-
@Appender(_index_shared_docs["_get_grouper_for_level"])
1563-
def _get_grouper_for_level(self, mapper, level=None):
15641548
assert level is None or level == 0
15651549
if mapper is None:
15661550
grouper = self
@@ -2156,9 +2140,8 @@ def notna(self):
21562140

21572141
notnull = notna
21582142

2159-
_index_shared_docs[
2160-
"fillna"
2161-
] = """
2143+
def fillna(self, value=None, downcast=None):
2144+
"""
21622145
Fill NA/NaN values with the specified value.
21632146
21642147
Parameters
@@ -2175,9 +2158,6 @@ def notna(self):
21752158
-------
21762159
filled : Index
21772160
"""
2178-
2179-
@Appender(_index_shared_docs["fillna"])
2180-
def fillna(self, value=None, downcast=None):
21812161
self._assert_can_do_op(value)
21822162
if self.hasnans:
21832163
result = self.putmask(self._isnan, value)
@@ -2187,9 +2167,8 @@ def fillna(self, value=None, downcast=None):
21872167
return Index(result, name=self.name)
21882168
return self._shallow_copy()
21892169

2190-
_index_shared_docs[
2191-
"dropna"
2192-
] = """
2170+
def dropna(self, how="any"):
2171+
"""
21932172
Return Index without NA/NaN values.
21942173
21952174
Parameters
@@ -2202,9 +2181,6 @@ def fillna(self, value=None, downcast=None):
22022181
-------
22032182
valid : Index
22042183
"""
2205-
2206-
@Appender(_index_shared_docs["dropna"])
2207-
def dropna(self, how="any"):
22082184
if how not in ("any", "all"):
22092185
raise ValueError(f"invalid how option: {how}")
22102186

@@ -2215,9 +2191,8 @@ def dropna(self, how="any"):
22152191
# --------------------------------------------------------------------
22162192
# Uniqueness Methods
22172193

2218-
_index_shared_docs[
2219-
"index_unique"
2220-
] = """
2194+
def unique(self, level=None):
2195+
"""
22212196
Return unique values in the index. Uniques are returned in order
22222197
of appearance, this does NOT sort.
22232198
@@ -2237,9 +2212,6 @@ def dropna(self, how="any"):
22372212
unique
22382213
Series.unique
22392214
"""
2240-
2241-
@Appender(_index_shared_docs["index_unique"] % _index_doc_kwargs)
2242-
def unique(self, level=None):
22432215
if level is not None:
22442216
self._validate_index_level(level)
22452217
result = super().unique()
@@ -2625,9 +2597,9 @@ def _union(self, other, sort):
26252597
def _wrap_setop_result(self, other, result):
26262598
return self._constructor(result, name=get_op_result_name(self, other))
26272599

2628-
_index_shared_docs[
2629-
"intersection"
2630-
] = """
2600+
# TODO: standardize return type of non-union setops type(self vs other)
2601+
def intersection(self, other, sort=False):
2602+
"""
26312603
Form the intersection of two Index objects.
26322604
26332605
This returns a new Index with elements common to the index and `other`.
@@ -2661,10 +2633,6 @@ def _wrap_setop_result(self, other, result):
26612633
>>> idx1.intersection(idx2)
26622634
Int64Index([3, 4], dtype='int64')
26632635
"""
2664-
2665-
# TODO: standardize return type of non-union setops type(self vs other)
2666-
@Appender(_index_shared_docs["intersection"])
2667-
def intersection(self, other, sort=False):
26682636
self._validate_sort_keyword(sort)
26692637
self._assert_can_do_setop(other)
26702638
other = ensure_index(other)
@@ -2868,9 +2836,8 @@ def _convert_can_do_setop(self, other):
28682836
# --------------------------------------------------------------------
28692837
# Indexing Methods
28702838

2871-
_index_shared_docs[
2872-
"get_loc"
2873-
] = """
2839+
def get_loc(self, key, method=None, tolerance=None):
2840+
"""
28742841
Get integer location, slice or boolean mask for requested label.
28752842
28762843
Parameters
@@ -2907,9 +2874,6 @@ def _convert_can_do_setop(self, other):
29072874
>>> non_monotonic_index.get_loc('b')
29082875
array([False, True, False, True], dtype=bool)
29092876
"""
2910-
2911-
@Appender(_index_shared_docs["get_loc"])
2912-
def get_loc(self, key, method=None, tolerance=None):
29132877
if method is None:
29142878
if tolerance is not None:
29152879
raise ValueError(
@@ -3121,19 +3085,15 @@ def _filter_indexer_tolerance(
31213085
# --------------------------------------------------------------------
31223086
# Indexer Conversion Methods
31233087

3124-
_index_shared_docs[
3125-
"_convert_scalar_indexer"
3126-
] = """
3088+
def _convert_scalar_indexer(self, key, kind=None):
3089+
"""
31273090
Convert a scalar indexer.
31283091
31293092
Parameters
31303093
----------
31313094
key : label of the slice bound
31323095
kind : {'loc', 'getitem', 'iloc'} or None
3133-
"""
3134-
3135-
@Appender(_index_shared_docs["_convert_scalar_indexer"])
3136-
def _convert_scalar_indexer(self, key, kind=None):
3096+
"""
31373097
assert kind in ["loc", "getitem", "iloc", None]
31383098

31393099
if kind == "iloc":
@@ -3171,9 +3131,8 @@ def _convert_scalar_indexer(self, key, kind=None):
31713131

31723132
return key
31733133

3174-
_index_shared_docs[
3175-
"_convert_slice_indexer"
3176-
] = """
3134+
def _convert_slice_indexer(self, key: slice, kind=None):
3135+
"""
31773136
Convert a slice indexer.
31783137
31793138
By definition, these are labels unless 'iloc' is passed in.
@@ -3183,10 +3142,7 @@ def _convert_scalar_indexer(self, key, kind=None):
31833142
----------
31843143
key : label of the slice bound
31853144
kind : {'loc', 'getitem', 'iloc'} or None
3186-
"""
3187-
3188-
@Appender(_index_shared_docs["_convert_slice_indexer"])
3189-
def _convert_slice_indexer(self, key: slice, kind=None):
3145+
"""
31903146
assert kind in ["loc", "getitem", "iloc", None]
31913147

31923148
# validate iloc
@@ -3266,9 +3222,8 @@ def _convert_listlike_indexer(self, keyarr, kind=None):
32663222
indexer = self._convert_list_indexer(keyarr, kind=kind)
32673223
return indexer, keyarr
32683224

3269-
_index_shared_docs[
3270-
"_convert_arr_indexer"
3271-
] = """
3225+
def _convert_arr_indexer(self, keyarr):
3226+
"""
32723227
Convert an array-like indexer to the appropriate dtype.
32733228
32743229
Parameters
@@ -3279,16 +3234,12 @@ def _convert_listlike_indexer(self, keyarr, kind=None):
32793234
Returns
32803235
-------
32813236
converted_keyarr : array-like
3282-
"""
3283-
3284-
@Appender(_index_shared_docs["_convert_arr_indexer"])
3285-
def _convert_arr_indexer(self, keyarr):
3237+
"""
32863238
keyarr = com.asarray_tuplesafe(keyarr)
32873239
return keyarr
32883240

3289-
_index_shared_docs[
3290-
"_convert_index_indexer"
3291-
] = """
3241+
def _convert_index_indexer(self, keyarr):
3242+
"""
32923243
Convert an Index indexer to the appropriate dtype.
32933244
32943245
Parameters
@@ -3299,15 +3250,11 @@ def _convert_arr_indexer(self, keyarr):
32993250
Returns
33003251
-------
33013252
converted_keyarr : Index (or sub-class)
3302-
"""
3303-
3304-
@Appender(_index_shared_docs["_convert_index_indexer"])
3305-
def _convert_index_indexer(self, keyarr):
3253+
"""
33063254
return keyarr
33073255

3308-
_index_shared_docs[
3309-
"_convert_list_indexer"
3310-
] = """
3256+
def _convert_list_indexer(self, keyarr, kind=None):
3257+
"""
33113258
Convert a list-like indexer to the appropriate dtype.
33123259
33133260
Parameters
@@ -3319,10 +3266,7 @@ def _convert_index_indexer(self, keyarr):
33193266
Returns
33203267
-------
33213268
positional indexer or None
3322-
"""
3323-
3324-
@Appender(_index_shared_docs["_convert_list_indexer"])
3325-
def _convert_list_indexer(self, keyarr, kind=None):
3269+
"""
33263270
if (
33273271
kind in [None, "iloc"]
33283272
and is_integer_dtype(keyarr)
@@ -3502,9 +3446,8 @@ def _reindex_non_unique(self, target):
35023446
# --------------------------------------------------------------------
35033447
# Join Methods
35043448

3505-
_index_shared_docs[
3506-
"join"
3507-
] = """
3449+
def join(self, other, how="left", level=None, return_indexers=False, sort=False):
3450+
"""
35083451
Compute join_index and indexers to conform data
35093452
structures to the new index.
35103453
@@ -3522,9 +3465,6 @@ def _reindex_non_unique(self, target):
35223465
-------
35233466
join_index, (left_indexer, right_indexer)
35243467
"""
3525-
3526-
@Appender(_index_shared_docs["join"])
3527-
def join(self, other, how="left", level=None, return_indexers=False, sort=False):
35283468
self_is_mi = isinstance(self, ABCMultiIndex)
35293469
other_is_mi = isinstance(other, ABCMultiIndex)
35303470

@@ -4033,9 +3973,8 @@ def memory_usage(self, deep: bool = False) -> int:
40333973
result += self._engine.sizeof(deep=deep)
40343974
return result
40353975

4036-
_index_shared_docs[
4037-
"where"
4038-
] = """
3976+
def where(self, cond, other=None):
3977+
"""
40393978
Return an Index of same shape as self and whose corresponding
40403979
entries are from self where cond is True and otherwise are from
40413980
other.
@@ -4049,9 +3988,6 @@ def memory_usage(self, deep: bool = False) -> int:
40493988
-------
40503989
Index
40513990
"""
4052-
4053-
@Appender(_index_shared_docs["where"])
4054-
def where(self, cond, other=None):
40553991
if other is None:
40563992
other = self._na_value
40573993

@@ -4146,9 +4082,8 @@ def is_type_compatible(self, kind) -> bool:
41464082
"""
41474083
return kind == self.inferred_type
41484084

4149-
_index_shared_docs[
4150-
"contains"
4151-
] = """
4085+
def __contains__(self, key: Any) -> bool:
4086+
"""
41524087
Return a boolean indicating whether the provided key is in the index.
41534088
41544089
Parameters
@@ -4177,9 +4112,6 @@ def is_type_compatible(self, kind) -> bool:
41774112
>>> 6 in idx
41784113
False
41794114
"""
4180-
4181-
@Appender(_index_shared_docs["contains"] % _index_doc_kwargs)
4182-
def __contains__(self, key: Any) -> bool:
41834115
hash(key)
41844116
try:
41854117
return key in self._engine
@@ -5020,9 +4952,8 @@ def _validate_indexer(self, form: str_t, key, kind: str_t):
50204952
else:
50214953
self._invalid_indexer(form, key)
50224954

5023-
_index_shared_docs[
5024-
"_maybe_cast_slice_bound"
5025-
] = """
4955+
def _maybe_cast_slice_bound(self, label, side: str_t, kind):
4956+
"""
50264957
This function should be overloaded in subclasses that allow non-trivial
50274958
casting on label-slice bounds, e.g. datetime-like indices allowing
50284959
strings containing formatted datetimes.
@@ -5041,9 +4972,6 @@ def _validate_indexer(self, form: str_t, key, kind: str_t):
50414972
-----
50424973
Value of `side` parameter should be validated in caller.
50434974
"""
5044-
5045-
@Appender(_index_shared_docs["_maybe_cast_slice_bound"])
5046-
def _maybe_cast_slice_bound(self, label, side: str_t, kind):
50474975
assert kind in ["loc", "getitem", None]
50484976

50494977
# We are a plain index here (sub-class override this method if they

0 commit comments

Comments
 (0)