Skip to content

Commit 1071264

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53336)
* Examples * Changed Index.copy * Corrected Float32Dtype & Float64Dtype
1 parent 566d142 commit 1071264

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

ci/code_checks.sh

-7
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
170170
pandas.Period.asfreq \
171171
pandas.Period.now \
172172
pandas.arrays.PeriodArray \
173-
pandas.arrays.IntervalArray.from_arrays \
174-
pandas.arrays.IntervalArray.to_tuples \
175173
pandas.Int8Dtype \
176174
pandas.Int16Dtype \
177175
pandas.Int32Dtype \
@@ -181,8 +179,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
181179
pandas.UInt32Dtype \
182180
pandas.UInt64Dtype \
183181
pandas.NA \
184-
pandas.Float32Dtype \
185-
pandas.Float64Dtype \
186182
pandas.CategoricalDtype.categories \
187183
pandas.CategoricalDtype.ordered \
188184
pandas.Categorical.dtype \
@@ -258,9 +254,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
258254
pandas.util.hash_pandas_object \
259255
pandas_object \
260256
pandas.api.interchange.from_dataframe \
261-
pandas.Index.T \
262-
pandas.Index.memory_usage \
263-
pandas.Index.copy \
264257
pandas.Index.drop \
265258
pandas.Index.identical \
266259
pandas.Index.insert \

pandas/core/arrays/floating.py

+14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ class FloatingArray(NumericArray):
134134
Methods
135135
-------
136136
None
137+
138+
Examples
139+
--------
140+
For Float32Dtype:
141+
142+
>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float32Dtype())
143+
>>> ser.dtype
144+
Float32Dtype()
145+
146+
For Float64Dtype:
147+
148+
>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float64Dtype())
149+
>>> ser.dtype
150+
Float64Dtype()
137151
"""
138152

139153
# create the Dtype

pandas/core/arrays/interval.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ def from_breaks(
509509
"name": "",
510510
"examples": textwrap.dedent(
511511
"""\
512+
Examples
513+
--------
512514
>>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3])
513515
<IntervalArray>
514516
[(0, 1], (1, 2], (2, 3]]
@@ -1635,9 +1637,8 @@ def __arrow_array__(self, type=None):
16351637

16361638
return pyarrow.ExtensionArray.from_storage(interval_type, storage_array)
16371639

1638-
_interval_shared_docs[
1639-
"to_tuples"
1640-
] = """
1640+
_interval_shared_docs["to_tuples"] = textwrap.dedent(
1641+
"""
16411642
Return an %(return_type)s of tuples of the form (left, right).
16421643
16431644
Parameters
@@ -1651,9 +1652,27 @@ def __arrow_array__(self, type=None):
16511652
tuples: %(return_type)s
16521653
%(examples)s\
16531654
"""
1655+
)
16541656

16551657
@Appender(
1656-
_interval_shared_docs["to_tuples"] % {"return_type": "ndarray", "examples": ""}
1658+
_interval_shared_docs["to_tuples"]
1659+
% {
1660+
"return_type": "ndarray",
1661+
"examples": textwrap.dedent(
1662+
"""\
1663+
1664+
Examples
1665+
--------
1666+
>>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
1667+
>>> idx
1668+
<IntervalArray>
1669+
[(0, 1], (1, 2]]
1670+
Length: 2, dtype: interval[int64, right]
1671+
>>> idx.to_tuples()
1672+
array([(0, 1), (1, 2)], dtype=object)
1673+
"""
1674+
),
1675+
}
16571676
)
16581677
def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
16591678
tuples = com.asarray_tuplesafe(zip(self._left, self._right))

pandas/core/base.py

+14
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ def transpose(self, *args, **kwargs) -> Self:
300300
301301
Examples
302302
--------
303+
For Series:
304+
303305
>>> s = pd.Series(['Ant', 'Bear', 'Cow'])
304306
>>> s
305307
0 Ant
@@ -311,6 +313,12 @@ def transpose(self, *args, **kwargs) -> Self:
311313
1 Bear
312314
2 Cow
313315
dtype: object
316+
317+
For Index:
318+
319+
>>> idx = pd.Index([1, 2, 3])
320+
>>> idx.T
321+
Index([1, 2, 3], dtype='int64')
314322
""",
315323
)
316324

@@ -1088,6 +1096,12 @@ def _memory_usage(self, deep: bool = False) -> int:
10881096
-----
10891097
Memory usage does not include memory consumed by elements that
10901098
are not components of the array if deep=False or if used on PyPy
1099+
1100+
Examples
1101+
--------
1102+
>>> idx = pd.Index([1, 2, 3])
1103+
>>> idx.memory_usage()
1104+
24
10911105
"""
10921106
if hasattr(self.array, "memory_usage"):
10931107
return self.array.memory_usage( # pyright: ignore[reportGeneralTypeIssues]

pandas/core/indexes/base.py

+7
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,13 @@ def copy(
12301230
-----
12311231
In most cases, there should be no functional difference from using
12321232
``deep``, but if ``deep`` is passed it will attempt to deepcopy.
1233+
1234+
Examples
1235+
--------
1236+
>>> idx = pd.Index(['a', 'b', 'c'])
1237+
>>> new_idx = idx.copy()
1238+
>>> idx is new_idx
1239+
False
12331240
"""
12341241

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

0 commit comments

Comments
 (0)