diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 472bd78e4d3bc..5870a9ad8d60b 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -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 \ diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index a622de742a840..c3fbd3ee4853e 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 3931b12e06f9b..16b8e9770e7f3 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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): diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 50fc5231a3a76..ea4d10c06efe3 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -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 @@ -772,6 +773,13 @@ 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 @@ -779,6 +787,13 @@ def unit(self) -> str_type: 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 @@ -967,6 +982,12 @@ def __reduce__(self): def freq(self): """ The frequency object of this PeriodDtype. + + Examples + -------- + >>> dtype = pd.PeriodDtype(freq='D') + >>> dtype.freq + """ return self._freq @@ -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 + dtype('int64') """ return self._subtype @@ -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