Skip to content

DOC: Fixing EX01 - Added examples #53336

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

Merged
merged 5 commits into from
May 23, 2023
Merged
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
7 changes: 0 additions & 7 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.Period.asfreq \
pandas.Period.now \
pandas.arrays.PeriodArray \
pandas.arrays.IntervalArray.from_arrays \
pandas.arrays.IntervalArray.to_tuples \
pandas.Int8Dtype \
pandas.Int16Dtype \
pandas.Int32Dtype \
Expand All @@ -181,8 +179,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.UInt32Dtype \
pandas.UInt64Dtype \
pandas.NA \
pandas.Float32Dtype \
pandas.Float64Dtype \
pandas.CategoricalDtype.categories \
pandas.CategoricalDtype.ordered \
pandas.Categorical.dtype \
Expand Down Expand Up @@ -258,9 +254,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.util.hash_pandas_object \
pandas_object \
pandas.api.interchange.from_dataframe \
pandas.Index.T \
pandas.Index.memory_usage \
pandas.Index.copy \
pandas.Index.drop \
pandas.Index.identical \
pandas.Index.insert \
Expand Down
14 changes: 14 additions & 0 deletions pandas/core/arrays/floating.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ class FloatingArray(NumericArray):
Methods
-------
None

Examples
--------
For Float32Dtype:

>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float32Dtype())
>>> ser.dtype
Float32Dtype()

For Float64Dtype:

>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float64Dtype())
>>> ser.dtype
Float64Dtype()
"""

# create the Dtype
Expand Down
27 changes: 23 additions & 4 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ def from_breaks(
"name": "",
"examples": textwrap.dedent(
"""\
Examples
--------
>>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3])
<IntervalArray>
[(0, 1], (1, 2], (2, 3]]
Expand Down Expand Up @@ -1635,9 +1637,8 @@ def __arrow_array__(self, type=None):

return pyarrow.ExtensionArray.from_storage(interval_type, storage_array)

_interval_shared_docs[
"to_tuples"
] = """
_interval_shared_docs["to_tuples"] = textwrap.dedent(
"""
Return an %(return_type)s of tuples of the form (left, right).

Parameters
Expand All @@ -1651,9 +1652,27 @@ def __arrow_array__(self, type=None):
tuples: %(return_type)s
%(examples)s\
"""
)

@Appender(
_interval_shared_docs["to_tuples"] % {"return_type": "ndarray", "examples": ""}
_interval_shared_docs["to_tuples"]
% {
"return_type": "ndarray",
"examples": textwrap.dedent(
"""\

Examples
--------
>>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
>>> idx
<IntervalArray>
[(0, 1], (1, 2]]
Length: 2, dtype: interval[int64, right]
>>> idx.to_tuples()
array([(0, 1), (1, 2)], dtype=object)
"""
),
}
)
def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
Expand Down
14 changes: 14 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def transpose(self, *args, **kwargs) -> Self:

Examples
--------
For Series:

>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
>>> s
0 Ant
Expand All @@ -311,6 +313,12 @@ def transpose(self, *args, **kwargs) -> Self:
1 Bear
2 Cow
dtype: object

For Index:

>>> idx = pd.Index([1, 2, 3])
>>> idx.T
Index([1, 2, 3], dtype='int64')
""",
)

Expand Down Expand Up @@ -1088,6 +1096,12 @@ def _memory_usage(self, deep: bool = False) -> int:
-----
Memory usage does not include memory consumed by elements that
are not components of the array if deep=False or if used on PyPy

Examples
--------
>>> idx = pd.Index([1, 2, 3])
>>> idx.memory_usage()
24
"""
if hasattr(self.array, "memory_usage"):
return self.array.memory_usage( # pyright: ignore[reportGeneralTypeIssues]
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,13 @@ def copy(
-----
In most cases, there should be no functional difference from using
``deep``, but if ``deep`` is passed it will attempt to deepcopy.

Examples
--------
>>> idx = pd.Index(['a', 'b', 'c'])
>>> new_idx = idx.copy()
>>> idx is new_idx
False
"""

name = self._validate_names(name=name, deep=deep)[0]
Expand Down