Skip to content

Commit 6be29bf

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53818)
* Examples api.types, Sparse, TZDtype * Edited code_checks * Changed tz to zoneinfo * Added ZoneInfo for tz param
1 parent 42b5fbb commit 6be29bf

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

ci/code_checks.sh

-11
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
105105
pandas.errors.UnsupportedFunctionCall \
106106
pandas.test \
107107
pandas.NaT \
108-
pandas.SparseDtype \
109-
pandas.DatetimeTZDtype.unit \
110-
pandas.DatetimeTZDtype.tz \
111-
pandas.PeriodDtype.freq \
112-
pandas.IntervalDtype.subtype \
113-
pandas_dtype \
114-
pandas.api.types.is_bool \
115-
pandas.api.types.is_complex \
116-
pandas.api.types.is_float \
117-
pandas.api.types.is_integer \
118-
pandas.api.types.pandas_dtype \
119108
pandas.read_clipboard \
120109
pandas.ExcelFile \
121110
pandas.ExcelFile.parse \

pandas/_libs/lib.pyx

+32
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,14 @@ def is_float(obj: object) -> bool:
10561056
Returns
10571057
-------
10581058
bool
1059+
1060+
Examples
1061+
--------
1062+
>>> pd.api.types.is_float(1.0)
1063+
True
1064+
1065+
>>> pd.api.types.is_float(1)
1066+
False
10591067
"""
10601068
return util.is_float_object(obj)
10611069

@@ -1067,6 +1075,14 @@ def is_integer(obj: object) -> bool:
10671075
Returns
10681076
-------
10691077
bool
1078+
1079+
Examples
1080+
--------
1081+
>>> pd.api.types.is_integer(1)
1082+
True
1083+
1084+
>>> pd.api.types.is_integer(1.0)
1085+
False
10701086
"""
10711087
return util.is_integer_object(obj)
10721088

@@ -1089,6 +1105,14 @@ def is_bool(obj: object) -> bool:
10891105
Returns
10901106
-------
10911107
bool
1108+
1109+
Examples
1110+
--------
1111+
>>> pd.api.types.is_bool(True)
1112+
True
1113+
1114+
>>> pd.api.types.is_bool(1)
1115+
False
10921116
"""
10931117
return util.is_bool_object(obj)
10941118

@@ -1100,6 +1124,14 @@ def is_complex(obj: object) -> bool:
11001124
Returns
11011125
-------
11021126
bool
1127+
1128+
Examples
1129+
--------
1130+
>>> pd.api.types.is_complex(1 + 1j)
1131+
True
1132+
1133+
>>> pd.api.types.is_complex(1)
1134+
False
11031135
"""
11041136
return util.is_complex_object(obj)
11051137

pandas/core/dtypes/common.py

+5
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,11 @@ def pandas_dtype(dtype) -> DtypeObj:
16031603
Raises
16041604
------
16051605
TypeError if not a dtype
1606+
1607+
Examples
1608+
--------
1609+
>>> pd.api.types.pandas_dtype(int)
1610+
dtype('int64')
16061611
"""
16071612
# short-circuit
16081613
if isinstance(dtype, np.ndarray):

pandas/core/dtypes/dtypes.py

+42-4
Original file line numberDiff line numberDiff line change
@@ -697,16 +697,17 @@ class DatetimeTZDtype(PandasExtensionDtype):
697697
698698
Raises
699699
------
700-
pytz.UnknownTimeZoneError
700+
ZoneInfoNotFoundError
701701
When the requested timezone cannot be found.
702702
703703
Examples
704704
--------
705-
>>> pd.DatetimeTZDtype(tz='UTC')
705+
>>> from zoneinfo import ZoneInfo
706+
>>> pd.DatetimeTZDtype(tz=ZoneInfo('UTC'))
706707
datetime64[ns, UTC]
707708
708-
>>> pd.DatetimeTZDtype(tz='dateutil/US/Central')
709-
datetime64[ns, tzfile('/usr/share/zoneinfo/US/Central')]
709+
>>> pd.DatetimeTZDtype(tz=ZoneInfo('Europe/Paris'))
710+
datetime64[ns, Europe/Paris]
710711
"""
711712

712713
type: type[Timestamp] = Timestamp
@@ -772,13 +773,27 @@ def _creso(self) -> int:
772773
def unit(self) -> str_type:
773774
"""
774775
The precision of the datetime data.
776+
777+
Examples
778+
--------
779+
>>> from zoneinfo import ZoneInfo
780+
>>> dtype = pd.DatetimeTZDtype(tz=ZoneInfo('America/Los_Angeles'))
781+
>>> dtype.unit
782+
'ns'
775783
"""
776784
return self._unit
777785

778786
@property
779787
def tz(self) -> tzinfo:
780788
"""
781789
The timezone.
790+
791+
Examples
792+
--------
793+
>>> from zoneinfo import ZoneInfo
794+
>>> dtype = pd.DatetimeTZDtype(tz=ZoneInfo('America/Los_Angeles'))
795+
>>> dtype.tz
796+
zoneinfo.ZoneInfo(key='America/Los_Angeles')
782797
"""
783798
return self._tz
784799

@@ -967,6 +982,12 @@ def __reduce__(self):
967982
def freq(self):
968983
"""
969984
The frequency object of this PeriodDtype.
985+
986+
Examples
987+
--------
988+
>>> dtype = pd.PeriodDtype(freq='D')
989+
>>> dtype.freq
990+
<Day>
970991
"""
971992
return self._freq
972993

@@ -1217,6 +1238,12 @@ def closed(self) -> IntervalClosedType:
12171238
def subtype(self):
12181239
"""
12191240
The dtype of the Interval bounds.
1241+
1242+
Examples
1243+
--------
1244+
>>> dtype = pd.IntervalDtype(subtype='int64', closed='both')
1245+
>>> dtype.subtype
1246+
dtype('int64')
12201247
"""
12211248
return self._subtype
12221249

@@ -1565,6 +1592,17 @@ class SparseDtype(ExtensionDtype):
15651592
Methods
15661593
-------
15671594
None
1595+
1596+
Examples
1597+
--------
1598+
>>> ser = pd.Series([1, 0, 0], dtype=pd.SparseDtype(dtype=int, fill_value=0))
1599+
>>> ser
1600+
0 1
1601+
1 0
1602+
2 0
1603+
dtype: Sparse[int64, 0]
1604+
>>> ser.sparse.density
1605+
0.3333333333333333
15681606
"""
15691607

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

0 commit comments

Comments
 (0)