Skip to content

Commit bcfdd62

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53536)
Examples
1 parent d2535c1 commit bcfdd62

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8282
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
8383
pandas.Series.backfill \
8484
pandas.Series.pad \
85-
pandas.DataFrame.sparse \
86-
pandas.Series.attrs \
87-
pandas.Series.plot \
8885
pandas.Series.hist \
89-
pandas.Series.to_string \
90-
pandas.errors.AbstractMethodError \
9186
pandas.errors.AccessorRegistrationWarning \
9287
pandas.errors.AttributeConflictWarning \
9388
pandas.errors.DataError \

pandas/core/arrays/sparse/accessor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ def to_dense(self) -> Series:
234234
class SparseFrameAccessor(BaseAccessor, PandasDelegate):
235235
"""
236236
DataFrame accessor for sparse data.
237+
238+
Examples
239+
--------
240+
>>> df = pd.DataFrame({"a": [1, 2, 0, 0],
241+
... "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
242+
>>> df.sparse.density
243+
0.5
237244
"""
238245

239246
def _validate(self, data):

pandas/core/generic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ def attrs(self) -> dict[Hashable, Any]:
334334
See Also
335335
--------
336336
DataFrame.flags : Global flags applying to this object.
337+
338+
Examples
339+
--------
340+
>>> ser = pd.Series([1, 2, 3])
341+
>>> ser.attrs = {"A": [10, 20, 30]}
342+
>>> ser.attrs
343+
{'A': [10, 20, 30]}
337344
"""
338345
if self._attrs is None:
339346
self._attrs = {}

pandas/core/series.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,12 @@ def to_string(
17131713
-------
17141714
str or None
17151715
String representation of Series if ``buf=None``, otherwise None.
1716+
1717+
Examples
1718+
--------
1719+
>>> ser = pd.Series([1, 2, 3]).to_string()
1720+
>>> ser
1721+
'0 1\\n1 2\\n2 3'
17161722
"""
17171723
formatter = fmt.SeriesFormatter(
17181724
self,

pandas/errors/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ class AccessorRegistrationWarning(Warning):
193193
class AbstractMethodError(NotImplementedError):
194194
"""
195195
Raise this error instead of NotImplementedError for abstract methods.
196+
197+
Examples
198+
--------
199+
>>> class Foo:
200+
... @classmethod
201+
... def classmethod(cls):
202+
... raise pd.errors.AbstractMethodError(cls, methodtype="classmethod")
203+
... def method(self):
204+
... raise pd.errors.AbstractMethodError(self)
205+
>>> test = Foo.classmethod()
206+
Traceback (most recent call last):
207+
AbstractMethodError: This classmethod must be defined in the concrete class Foo
208+
209+
>>> test2 = Foo().method()
210+
Traceback (most recent call last):
211+
AbstractMethodError: This classmethod must be defined in the concrete class Foo
196212
"""
197213

198214
def __init__(self, class_instance, methodtype: str = "method") -> None:

pandas/plotting/_core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,15 @@ class PlotAccessor(PandasObject):
775775
for bar plot layout by `position` keyword.
776776
From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5
777777
(center)
778+
779+
Examples
780+
--------
781+
782+
.. plot::
783+
:context: close-figs
784+
785+
>>> ser = pd.Series([1, 2, 3, 3])
786+
>>> plot = ser.plot(kind='hist', title="My plot")
778787
"""
779788

780789
_common_kinds = ("line", "bar", "barh", "kde", "density", "area", "hist", "box")

0 commit comments

Comments
 (0)