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
46 changes: 42 additions & 4 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,16 +697,17 @@ class DatetimeTZDtype(PandasExtensionDtype):

Raises
------
pytz.UnknownTimeZoneError
ZoneInfoNotFoundError
When the requested timezone cannot be found.

Examples
--------
>>> pd.DatetimeTZDtype(tz='UTC')
>>> from zoneinfo import ZoneInfo
>>> pd.DatetimeTZDtype(tz=ZoneInfo('UTC'))
datetime64[ns, UTC]

>>> pd.DatetimeTZDtype(tz='dateutil/US/Central')
datetime64[ns, tzfile('/usr/share/zoneinfo/US/Central')]
>>> pd.DatetimeTZDtype(tz=ZoneInfo('Europe/Paris'))
datetime64[ns, Europe/Paris]
"""

type: type[Timestamp] = Timestamp
Expand Down Expand Up @@ -772,13 +773,27 @@ def _creso(self) -> int:
def unit(self) -> str_type:
"""
The precision of the datetime data.

Examples
--------
>>> from zoneinfo import ZoneInfo
>>> dtype = pd.DatetimeTZDtype(tz=ZoneInfo('America/Los_Angeles'))
>>> dtype.unit
'ns'
"""
return self._unit

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

Examples
--------
>>> from zoneinfo import ZoneInfo
>>> dtype = pd.DatetimeTZDtype(tz=ZoneInfo('America/Los_Angeles'))
>>> dtype.tz
zoneinfo.ZoneInfo(key='America/Los_Angeles')
"""
return self._tz

Expand Down Expand Up @@ -967,6 +982,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 +1238,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 +1592,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