Skip to content

DOC: Fixing EX01 - Added examples #53818

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 8 commits into from
Jun 26, 2023
11 changes: 0 additions & 11 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.errors.UnsupportedFunctionCall \
pandas.test \
pandas.NaT \
pandas.SparseDtype \
pandas.DatetimeTZDtype.unit \
pandas.DatetimeTZDtype.tz \
pandas.PeriodDtype.freq \
pandas.IntervalDtype.subtype \
pandas_dtype \
pandas.api.types.is_bool \
pandas.api.types.is_complex \
pandas.api.types.is_float \
pandas.api.types.is_integer \
pandas.api.types.pandas_dtype \
pandas.read_clipboard \
pandas.ExcelFile \
pandas.ExcelFile.parse \
Expand Down
32 changes: 32 additions & 0 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ def is_float(obj: object) -> bool:
Returns
-------
bool

Examples
--------
>>> pd.api.types.is_float(1.0)
True

>>> pd.api.types.is_float(1)
False
"""
return util.is_float_object(obj)

Expand All @@ -1067,6 +1075,14 @@ def is_integer(obj: object) -> bool:
Returns
-------
bool

Examples
--------
>>> pd.api.types.is_integer(1)
True

>>> pd.api.types.is_integer(1.0)
False
"""
return util.is_integer_object(obj)

Expand All @@ -1089,6 +1105,14 @@ def is_bool(obj: object) -> bool:
Returns
-------
bool

Examples
--------
>>> pd.api.types.is_bool(True)
True

>>> pd.api.types.is_bool(1)
False
"""
return util.is_bool_object(obj)

Expand All @@ -1100,6 +1124,14 @@ def is_complex(obj: object) -> bool:
Returns
-------
bool

Examples
--------
>>> pd.api.types.is_complex(1 + 1j)
True

>>> pd.api.types.is_complex(1)
False
"""
return util.is_complex_object(obj)

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,11 @@ def pandas_dtype(dtype) -> DtypeObj:
Raises
------
TypeError if not a dtype

Examples
--------
>>> pd.api.types.pandas_dtype(int)
dtype('int64')
"""
# short-circuit
if isinstance(dtype, np.ndarray):
Expand Down
35 changes: 35 additions & 0 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,25 @@ def _creso(self) -> int:
def unit(self) -> str_type:
"""
The precision of the datetime data.

Examples
--------
>>> dtype = pd.DatetimeTZDtype(tz='dateutil/US/Central')
Copy link
Member

Choose a reason for hiding this comment

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

Could you use zoneinfo for the tz argument for these examples?

Copy link
Member Author

@DeaMariaLeon DeaMariaLeon Jun 24, 2023

Choose a reason for hiding this comment

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

I used the example from the reference forDatetimeTZDtype because I wasn't familiar with it. It also uses dateutil. Here is the link.
Please tell me if I should change that.
EDIT: Working on this (updated after review but incorrectly)

>>> dtype.unit
'ns'
"""
return self._unit

@property
def tz(self) -> tzinfo:
"""
The timezone.

Examples
--------
>>> dtype = pd.DatetimeTZDtype(tz='dateutil/US/Central')
>>> dtype.tz
tzfile('/usr/share/zoneinfo/US/Central')
"""
return self._tz

Expand Down Expand Up @@ -967,6 +979,12 @@ def __reduce__(self):
def freq(self):
"""
The frequency object of this PeriodDtype.

Examples
--------
>>> dtype = pd.PeriodDtype(freq='D')
>>> dtype.freq
<Day>
"""
return self._freq

Expand Down Expand Up @@ -1217,6 +1235,12 @@ def closed(self) -> IntervalClosedType:
def subtype(self):
"""
The dtype of the Interval bounds.

Examples
--------
>>> dtype = pd.IntervalDtype(subtype='int64', closed='both')
>>> dtype.subtype
Copy link
Member

Choose a reason for hiding this comment

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

didn't know this existed, nice

dtype('int64')
"""
return self._subtype

Expand Down Expand Up @@ -1565,6 +1589,17 @@ class SparseDtype(ExtensionDtype):
Methods
-------
None

Examples
--------
>>> ser = pd.Series([1, 0, 0], dtype=pd.SparseDtype(dtype=int, fill_value=0))
>>> ser
0 1
1 0
2 0
dtype: Sparse[int64, 0]
>>> ser.sparse.density
0.3333333333333333
"""

# We include `_is_na_fill_value` in the metadata to avoid hash collisions
Expand Down