Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#48832: GL08 - Added missing docstrings #48977

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ def ravel(self, order: str_t = "C"):
return values.ravel(order=order)

def view(self, cls=None):
"""
Creates a new view from current Index.
"""

# we need to see if we are subclassing an
# index type here
Expand Down Expand Up @@ -1842,6 +1845,24 @@ def _get_default_index_names(
return names

def _get_names(self) -> FrozenList:
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is private, not sure if we want to have examples here.

Returns an array of index names.

Returns
-------
FrozenList

Examples
--------
>>> arrays = [[1, 1, 2], ['red', 'blue', 'green'], ['apple', 'orange', 'apple']]
>>> m1 = pd.MultiIndex.from_arrays(arrays, names=('number', 'color', 'fruits'))
>>> m1.names
FrozenList(['number', 'color', 'fruits'])

>>> m2 = pd.MultiIndex.from_arrays(arrays)
>>> m2.names
FrozenList([None, None, None])
"""
return FrozenList((self.name,))

def _set_names(self, values, *, level=None) -> None:
Expand Down
52 changes: 52 additions & 0 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,18 +800,70 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:

@cache_readonly
def left(self) -> Index:
"""
Returns an array of left bounds.

Returns
-------
:class:~`pandas.Index`

Examples
--------
>>> b = pd.IntervalIndex.from_tuples([(0, 1), (2, 3), (5, 10), (6, 8)])
>>> b.left
Int64Index([0, 2, 5, 6], dtype='int64')
"""
return Index(self._data.left, copy=False)

@cache_readonly
def right(self) -> Index:
"""
Returns an array of right bounds.

Returns
-------
:class:~`pandas.Index`

Examples
--------
>>> b = pd.IntervalIndex.from_tuples([(0, 1), (2, 3), (5, 10), (6, 8)])
>>> b.right
Int64Index([1, 3, 10, 8], dtype='int64')
"""
return Index(self._data.right, copy=False)

@cache_readonly
def mid(self) -> Index:
"""
Returns an array of midpoints of the intervals.

Returns
-------
:class:~`pandas.Index`

Examples
--------
>>> b = pd.IntervalIndex.from_tuples([(0, 1), (2, 3), (5, 10), (6, 8)])
>>> b.mid
Float64Index([0.5, 2.5, 7.5, 7.0], dtype='float64')
"""
return Index(self._data.mid, copy=False)

@property
def length(self) -> Index:
"""
Returns an array of lengths of intervals.

Returns
-------
:class:~`pandas.Index`

Examples
--------
>>> b = pd.IntervalIndex.from_tuples([(0, 1), (2, 3), (5, 10), (6, 8)])
>>> b.length
Int64Index([1, 1, 5, 2], dtype='int64')
"""
return Index(self._data.length, copy=False)

# --------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,20 @@ def size(self) -> int:

@cache_readonly
def levels(self) -> FrozenList:
"""
Returns array of arrays of unique values/categories from each index.

Returns
-------
FrozenList

Examples
--------
>>> arrays = [[1, 1, 2], ['red', 'blue', 'green'], ['apple', 'orange', 'apple']]
>>> m = pd.MultiIndex.from_arrays(arrays, names=('number', 'color', 'fruits'))
>>> m.levels
FrozenList([[1, 2], ['blue', 'green', 'red'], ['apple', 'orange']])
"""
# Use cache_readonly to ensure that self.get_locs doesn't repeatedly
# create new IndexEngine
# https://github.com/pandas-dev/pandas/issues/31648
Expand Down Expand Up @@ -1001,6 +1015,24 @@ def levshape(self) -> Shape:

@property
def codes(self):
"""
Returns an array of integers which are the positions of the actual values.

Returns
-------
FrozenList

See Also
--------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this link? MultiIndex is not really related to Categorical

Categorical.codes

Examples
--------
>>> arrays = [[1, 1, 2], ['red', 'blue', 'green'], ['apple', 'orange', 'apple']]
>>> m = pd.MultiIndex.from_arrays(arrays, names=('number', 'color', 'fruits'))
>>> m.codes
FrozenList([[0, 0, 1], [2, 0, 1], [0, 1, 0]])
"""
return self._codes

def _set_codes(
Expand Down