@@ -61,15 +61,19 @@ def string(
61
61
62
62
Examples
63
63
--------
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
67
67
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
69
71
large_string[pyarrow]
70
- >>> string(backend="pyarrow", mode="binary") # PyArrow binary
72
+ >>> print( string(backend="pyarrow", mode="binary") ) # PyArrow binary
71
73
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
73
77
large_binary[pyarrow]
74
78
"""
75
79
valid_modes = ["string" , "binary" ]
@@ -112,13 +116,13 @@ def datetime(
112
116
113
117
Examples
114
118
--------
115
- >>> pd. datetime() # Default numpy backend with ns unit
119
+ >>> print( datetime() ) # Default numpy backend with ns unit
116
120
datetime64[ns]
117
- >>> pd. datetime(unit="us") # Microsecond precision
121
+ >>> print( datetime(unit="us") ) # Microsecond precision
118
122
datetime64[us]
119
- >>> pd. datetime(tz="UTC") # Timezone-aware datetime
123
+ >>> print( datetime(tz="UTC") ) # Timezone-aware datetime
120
124
datetime64[ns, UTC]
121
- >>> pd. datetime(backend="pyarrow") # PyArrow backend
125
+ >>> print( datetime(backend="pyarrow") ) # PyArrow backend
122
126
timestamp[ns][pyarrow]
123
127
"""
124
128
valid_units = ["D" , "h" , "m" , "s" , "ms" , "us" , "ns" ]
@@ -155,13 +159,15 @@ def integer(
155
159
156
160
Examples
157
161
--------
158
- >>> integer() # Default: 64 bits with pandas backend
162
+ >>> print( integer() ) # Default: 64 bits with pandas backend
159
163
Int64
160
- >>> integer(bits=32) # 32-bit integer with pandas backend
164
+ >>> print( integer(bits=32) ) # 32-bit integer with pandas backend
161
165
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
165
171
int64[pyarrow]
166
172
"""
167
173
valid_bits = [8 , 16 , 32 , 64 ]
@@ -215,12 +221,12 @@ def floating(
215
221
216
222
Examples
217
223
--------
218
- >>> floating() # Default: 64 bits with NumPy backend
224
+ >>> print( floating() ) # Default: 64 bits with NumPy backend
219
225
Float64
220
- >>> floating(bits=32) # 32-bit float with NumPy backend
226
+ >>> print( floating(bits=32) ) # 32-bit float with NumPy backend
221
227
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]
224
230
"""
225
231
valid_bits = [32 , 64 ]
226
232
if bits not in valid_bits :
@@ -268,11 +274,11 @@ def decimal(
268
274
269
275
Examples
270
276
--------
271
- >>> decimal(precision=10, scale=2) # Decimal with 10 digits,
277
+ >>> print( decimal(precision=10, scale=2) ) # Decimal with 10 digits,
272
278
... # 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]
276
282
"""
277
283
if backend == "pyarrow" :
278
284
import pyarrow as pa
@@ -301,9 +307,9 @@ def boolean(
301
307
302
308
Examples
303
309
--------
304
- >>> boolean() # Default: NumPy backend
310
+ >>> print( boolean() ) # Default: NumPy backend
305
311
boolean
306
- >>> boolean(backend="pyarrow") # PyArrow backend
312
+ >>> print( boolean(backend="pyarrow") ) # PyArrow backend
307
313
bool[pyarrow]
308
314
"""
309
315
if backend == "numpy" :
@@ -339,16 +345,19 @@ def list_dtype(
339
345
340
346
Examples
341
347
--------
342
- >>> list_dtype() # Default numpy backend
348
+ >>> print( list_dtype() ) # Default numpy backend
343
349
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")
350
359
... ) # PyArrow large list
351
- large_list[ string] [pyarrow]
360
+ large_list<item: string> [pyarrow]
352
361
"""
353
362
if backend == "numpy" :
354
363
return np .dtype ("object" )
@@ -393,16 +402,19 @@ def categorical(
393
402
394
403
Examples
395
404
--------
396
- >>> categorical() # Default numpy backend
405
+ >>> print( categorical() ) # Default numpy backend
397
406
category
398
- >>> categorical(categories=["a", "b", "c"]) # With categories
407
+ >>> print( categorical(categories=["a", "b", "c"]) ) # With categories
399
408
category
400
- >>> categorical(ordered=True) # Ordered categories
409
+ >>> print( categorical(ordered=True) ) # Ordered categories
401
410
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]
406
418
"""
407
419
if backend == "numpy" :
408
420
return CategoricalDtype (categories = categories , ordered = ordered )
@@ -438,14 +450,14 @@ def interval(
438
450
439
451
Examples
440
452
--------
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
442
458
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]
449
461
"""
450
462
if backend == "numpy" :
451
463
return IntervalDtype (subtype = subtype , closed = closed )
@@ -496,11 +508,11 @@ def period(
496
508
497
509
Examples
498
510
--------
499
- >>> period() # Default numpy backend with daily frequency
511
+ >>> print( period() ) # Default numpy backend with daily frequency
500
512
period[D]
501
- >>> period(freq="M") # Monthly frequency
513
+ >>> print( period(freq="M") ) # Monthly frequency
502
514
period[M]
503
- >>> period(backend="pyarrow") # PyArrow backend
515
+ >>> print( period(backend="pyarrow") ) # PyArrow backend
504
516
month_day_nano_interval[pyarrow]
505
517
"""
506
518
if backend == "numpy" :
@@ -537,12 +549,12 @@ def sparse(
537
549
538
550
Examples
539
551
--------
540
- >>> sparse() # Default numpy backend
552
+ >>> print( sparse() ) # Default numpy backend
541
553
Sparse[float64, nan]
542
- >>> sparse(dtype="int64") # With specific dtype
554
+ >>> print( sparse(dtype="int64") ) # With specific dtype
543
555
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]
546
558
"""
547
559
if backend != "numpy" :
548
560
raise ValueError (
@@ -592,17 +604,17 @@ def date(
592
604
593
605
Examples
594
606
--------
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]
599
611
>>> import pandas as pd
600
612
>>> pd.Series(
601
613
... [pd.Timestamp("2023-01-01"), pd.Timestamp("2023-01-02")], dtype=date()
602
614
... )
603
615
0 2023-01-01
604
616
1 2023-01-02
605
- dtype: date32[pyarrow]
617
+ dtype: date32[day][ pyarrow]
606
618
"""
607
619
608
620
if backend != "pyarrow" :
@@ -637,9 +649,9 @@ def duration(
637
649
638
650
Examples
639
651
--------
640
- >>> duration() # Default PyArrow backend
652
+ >>> print( duration() ) # Default PyArrow backend
641
653
duration[ns][pyarrow]
642
- >>> duration(unit="s", backend="numpy") # NumPy backend
654
+ >>> print( duration(unit="s", backend="numpy") ) # NumPy backend
643
655
timedelta64[s]
644
656
"""
645
657
valid_units = ["ns" , "us" , "ms" , "s" ]
@@ -687,13 +699,14 @@ def map(
687
699
688
700
Examples
689
701
--------
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()))
691
704
map<int32, string>[pyarrow]
692
705
>>> import pandas as pd
693
706
>>> data = [[(1, "a"), (2, "b")], [(3, "c")]]
694
707
>>> 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' )]
697
710
dtype: map<int32, string>[pyarrow]
698
711
"""
699
712
if backend != "pyarrow" :
@@ -738,13 +751,14 @@ def struct(
738
751
739
752
Examples
740
753
--------
741
- >>> struct([("id", pa.int32()), ("name", pa.string())])
754
+ >>> import pyarrow as pa
755
+ >>> print(struct([("id", pa.int32()), ("name", pa.string())]))
742
756
struct<id: int32, name: string>[pyarrow]
743
757
>>> import pandas as pd
744
758
>>> data = [(1, "Alice"), (2, "Bob")]
745
759
>>> 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'}
748
762
dtype: struct<id: int32, name: string>[pyarrow]
749
763
"""
750
764
if backend == "pyarrow" :
0 commit comments