Skip to content

Commit 4aa3887

Browse files
committed
fixed docstrings
1 parent 5543674 commit 4aa3887

File tree

1 file changed

+81
-67
lines changed

1 file changed

+81
-67
lines changed

pandas/core/dtypes/factory.py

Lines changed: 81 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ def string(
6161
6262
Examples
6363
--------
64-
>>> string() # Default python backend with pd.NA
65-
string[python]
66-
>>> string(backend="pyarrow", mode="string") # PyArrow string backend
64+
>>> print(string()) # Default python backend with pd.NA
65+
string
66+
>>> print(string(backend="pyarrow", mode="string")) # PyArrow string backend
6767
string[pyarrow]
68-
>>> string(backend="pyarrow", mode="string", large=True) # PyArrow large string
68+
>>> print(
69+
... string(backend="pyarrow", mode="string", large=True)
70+
... ) # PyArrow large string
6971
large_string[pyarrow]
70-
>>> string(backend="pyarrow", mode="binary") # PyArrow binary
72+
>>> print(string(backend="pyarrow", mode="binary")) # PyArrow binary
7173
binary[pyarrow]
72-
>>> string(backend="pyarrow", mode="binary", large=True) # PyArrow large binary
74+
>>> print(
75+
... string(backend="pyarrow", mode="binary", large=True)
76+
... ) # PyArrow large binary
7377
large_binary[pyarrow]
7478
"""
7579
valid_modes = ["string", "binary"]
@@ -112,13 +116,13 @@ def datetime(
112116
113117
Examples
114118
--------
115-
>>> pd.datetime() # Default numpy backend with ns unit
119+
>>> print(datetime()) # Default numpy backend with ns unit
116120
datetime64[ns]
117-
>>> pd.datetime(unit="us") # Microsecond precision
121+
>>> print(datetime(unit="us")) # Microsecond precision
118122
datetime64[us]
119-
>>> pd.datetime(tz="UTC") # Timezone-aware datetime
123+
>>> print(datetime(tz="UTC")) # Timezone-aware datetime
120124
datetime64[ns, UTC]
121-
>>> pd.datetime(backend="pyarrow") # PyArrow backend
125+
>>> print(datetime(backend="pyarrow")) # PyArrow backend
122126
timestamp[ns][pyarrow]
123127
"""
124128
valid_units = ["D", "h", "m", "s", "ms", "us", "ns"]
@@ -155,13 +159,15 @@ def integer(
155159
156160
Examples
157161
--------
158-
>>> integer() # Default: 64 bits with pandas backend
162+
>>> print(integer()) # Default: 64 bits with pandas backend
159163
Int64
160-
>>> integer(bits=32) # 32-bit integer with pandas backend
164+
>>> print(integer(bits=32)) # 32-bit integer with pandas backend
161165
Int32
162-
>>> integer(bits=64, backend="numpy") # 64-bit integer with NumPy backend
163-
dtype('int64')
164-
>>> integer(bits=64, backend="pyarrow") # 64-bit integer with PyArrow backend
166+
>>> print(integer(bits=64, backend="numpy")) # 64-bit integer with NumPy backend
167+
int64
168+
>>> print(
169+
... integer(bits=64, backend="pyarrow")
170+
... ) # 64-bit integer with PyArrow backend
165171
int64[pyarrow]
166172
"""
167173
valid_bits = [8, 16, 32, 64]
@@ -215,12 +221,12 @@ def floating(
215221
216222
Examples
217223
--------
218-
>>> floating() # Default: 64 bits with NumPy backend
224+
>>> print(floating()) # Default: 64 bits with NumPy backend
219225
Float64
220-
>>> floating(bits=32) # 32-bit float with NumPy backend
226+
>>> print(floating(bits=32)) # 32-bit float with NumPy backend
221227
Float32
222-
>>> floating(bits=64, backend="pyarrow") # 64-bit float with PyArrow backend
223-
float64[pyarrow]
228+
>>> print(floating(bits=64, backend="pyarrow")) # 64-bit float with PyArrow backend
229+
double[pyarrow]
224230
"""
225231
valid_bits = [32, 64]
226232
if bits not in valid_bits:
@@ -268,11 +274,11 @@ def decimal(
268274
269275
Examples
270276
--------
271-
>>> decimal(precision=10, scale=2) # Decimal with 10 digits,
277+
>>> print(decimal(precision=10, scale=2)) # Decimal with 10 digits,
272278
... # 2 after the decimal point
273-
decimal128[10, 2][pyarrow]
274-
>>> decimal(precision=40, scale=5) # Larger precision, uses decimal256
275-
decimal256[40, 5][pyarrow]
279+
decimal128(10, 2)[pyarrow]
280+
>>> print(decimal(precision=40, scale=5)) # Larger precision, uses decimal256
281+
decimal256(40, 5)[pyarrow]
276282
"""
277283
if backend == "pyarrow":
278284
import pyarrow as pa
@@ -301,9 +307,9 @@ def boolean(
301307
302308
Examples
303309
--------
304-
>>> boolean() # Default: NumPy backend
310+
>>> print(boolean()) # Default: NumPy backend
305311
boolean
306-
>>> boolean(backend="pyarrow") # PyArrow backend
312+
>>> print(boolean(backend="pyarrow")) # PyArrow backend
307313
bool[pyarrow]
308314
"""
309315
if backend == "numpy":
@@ -339,16 +345,19 @@ def list_dtype(
339345
340346
Examples
341347
--------
342-
>>> list_dtype() # Default numpy backend
348+
>>> print(list_dtype()) # Default numpy backend
343349
object
344-
>>> list_dtype(backend="pyarrow") # PyArrow backend with default int64
345-
list[int64][pyarrow]
346-
>>> list_dtype(value_type=pa.string(), backend="pyarrow") # PyArrow with string
347-
list[string][pyarrow]
348-
>>> list_dtype(
349-
... value_type=pa.string(), large=True, backend="pyarrow"
350+
>>> print(list_dtype(backend="pyarrow")) # PyArrow backend with default int64
351+
list<item: int64>[pyarrow]
352+
>>> import pyarrow as pa
353+
>>> print(
354+
... list_dtype(value_type=pa.string(), backend="pyarrow")
355+
... ) # PyArrow with string
356+
list<item: string>[pyarrow]
357+
>>> print(
358+
... list_dtype(value_type=pa.string(), large=True, backend="pyarrow")
350359
... ) # PyArrow large list
351-
large_list[string][pyarrow]
360+
large_list<item: string>[pyarrow]
352361
"""
353362
if backend == "numpy":
354363
return np.dtype("object")
@@ -393,16 +402,19 @@ def categorical(
393402
394403
Examples
395404
--------
396-
>>> categorical() # Default numpy backend
405+
>>> print(categorical()) # Default numpy backend
397406
category
398-
>>> categorical(categories=["a", "b", "c"]) # With categories
407+
>>> print(categorical(categories=["a", "b", "c"])) # With categories
399408
category
400-
>>> categorical(ordered=True) # Ordered categories
409+
>>> print(categorical(ordered=True)) # Ordered categories
401410
category
402-
>>> categorical(backend="pyarrow") # PyArrow backend
403-
dictionary<values=string, indices=int32>[pyarrow]
404-
>>> categorical(index_type=pa.int64(), value_type=pa.int32(), backend="pyarrow")
405-
dictionary<values=int32, indices=int64>[pyarrow]
411+
>>> import pyarrow as pa
412+
>>> print(categorical(backend="pyarrow")) # PyArrow backend
413+
dictionary<values=string, indices=int32, ordered=0>[pyarrow]
414+
>>> print(
415+
... categorical(index_type=pa.int64(), value_type=pa.int32(), backend="pyarrow")
416+
... )
417+
dictionary<values=int32, indices=int64, ordered=0>[pyarrow]
406418
"""
407419
if backend == "numpy":
408420
return CategoricalDtype(categories=categories, ordered=ordered)
@@ -438,14 +450,14 @@ def interval(
438450
439451
Examples
440452
--------
441-
>>> interval() # Default numpy backend
453+
>>> print(interval()) # Default numpy backend
454+
interval
455+
>>> print(interval(subtype="int64")) # With specific subtype
456+
interval[int64, right]
457+
>>> print(interval(closed="both")) # Closed on both sides
442458
interval
443-
>>> interval(subtype="int64") # With specific subtype
444-
interval[int64]
445-
>>> interval(closed="both") # Closed on both sides
446-
interval[both]
447-
>>> interval(backend="pyarrow") # PyArrow backend
448-
interval[pyarrow]
459+
>>> print(interval(backend="pyarrow")) # PyArrow backend
460+
struct<left: double, right: double>[pyarrow]
449461
"""
450462
if backend == "numpy":
451463
return IntervalDtype(subtype=subtype, closed=closed)
@@ -496,11 +508,11 @@ def period(
496508
497509
Examples
498510
--------
499-
>>> period() # Default numpy backend with daily frequency
511+
>>> print(period()) # Default numpy backend with daily frequency
500512
period[D]
501-
>>> period(freq="M") # Monthly frequency
513+
>>> print(period(freq="M")) # Monthly frequency
502514
period[M]
503-
>>> period(backend="pyarrow") # PyArrow backend
515+
>>> print(period(backend="pyarrow")) # PyArrow backend
504516
month_day_nano_interval[pyarrow]
505517
"""
506518
if backend == "numpy":
@@ -537,12 +549,12 @@ def sparse(
537549
538550
Examples
539551
--------
540-
>>> sparse() # Default numpy backend
552+
>>> print(sparse()) # Default numpy backend
541553
Sparse[float64, nan]
542-
>>> sparse(dtype="int64") # With specific dtype
554+
>>> print(sparse(dtype="int64")) # With specific dtype
543555
Sparse[int64, 0]
544-
>>> sparse(fill_value=-1) # With specific fill value
545-
Sparse[float64, -1.0]
556+
>>> print(sparse(fill_value=-1)) # With specific fill value
557+
Sparse[float64, -1]
546558
"""
547559
if backend != "numpy":
548560
raise ValueError(
@@ -592,17 +604,17 @@ def date(
592604
593605
Examples
594606
--------
595-
>>> date() # Default day precision with PyArrow
596-
date32[pyarrow]
597-
>>> date(unit="ms") # Millisecond precision with PyArrow
598-
date64[pyarrow]
607+
>>> print(date()) # Default day precision with PyArrow
608+
date32[day][pyarrow]
609+
>>> print(date(unit="ms")) # Millisecond precision with PyArrow
610+
date64[ms][pyarrow]
599611
>>> import pandas as pd
600612
>>> pd.Series(
601613
... [pd.Timestamp("2023-01-01"), pd.Timestamp("2023-01-02")], dtype=date()
602614
... )
603615
0 2023-01-01
604616
1 2023-01-02
605-
dtype: date32[pyarrow]
617+
dtype: date32[day][pyarrow]
606618
"""
607619

608620
if backend != "pyarrow":
@@ -637,9 +649,9 @@ def duration(
637649
638650
Examples
639651
--------
640-
>>> duration() # Default PyArrow backend
652+
>>> print(duration()) # Default PyArrow backend
641653
duration[ns][pyarrow]
642-
>>> duration(unit="s", backend="numpy") # NumPy backend
654+
>>> print(duration(unit="s", backend="numpy")) # NumPy backend
643655
timedelta64[s]
644656
"""
645657
valid_units = ["ns", "us", "ms", "s"]
@@ -687,13 +699,14 @@ def map(
687699
688700
Examples
689701
--------
690-
>>> map(index_type=pa.int32(), value_type=pa.string())
702+
>>> import pyarrow as pa
703+
>>> print(map(index_type=pa.int32(), value_type=pa.string()))
691704
map<int32, string>[pyarrow]
692705
>>> import pandas as pd
693706
>>> data = [[(1, "a"), (2, "b")], [(3, "c")]]
694707
>>> pd.Series(data, dtype=map(pa.int32(), pa.string()))
695-
0 [(1, a), (2, b)]
696-
1 [(3, c)]
708+
0 [(1, 'a'), (2, 'b')]
709+
1 [(3, 'c')]
697710
dtype: map<int32, string>[pyarrow]
698711
"""
699712
if backend != "pyarrow":
@@ -738,13 +751,14 @@ def struct(
738751
739752
Examples
740753
--------
741-
>>> struct([("id", pa.int32()), ("name", pa.string())])
754+
>>> import pyarrow as pa
755+
>>> print(struct([("id", pa.int32()), ("name", pa.string())]))
742756
struct<id: int32, name: string>[pyarrow]
743757
>>> import pandas as pd
744758
>>> data = [(1, "Alice"), (2, "Bob")]
745759
>>> pd.Series(data, dtype=struct([("id", pa.int32()), ("name", pa.string())]))
746-
0 (1, Alice)
747-
1 (2, Bob)
760+
0 {'id': 1, 'name': 'Alice'}
761+
1 {'id': 2, 'name': 'Bob'}
748762
dtype: struct<id: int32, name: string>[pyarrow]
749763
"""
750764
if backend == "pyarrow":

0 commit comments

Comments
 (0)