DataTypes#
Daft provides simple DataTypes that are ubiquituous in many DataFrames such as numbers, strings and dates - all the way up to more complex types like tensors and images. Learn more about DataTypes in Daft User Guide.
DataType #
DataType()
A Daft DataType defines the type of all the values in an Expression or DataFrame column.
Methods:
Name | Description |
---|---|
binary | Create a Binary DataType: A string of bytes. |
bool | Create the Boolean DataType: Either |
date | Create a Date DataType: A date with a year, month and day. |
decimal128 | Fixed-precision decimal. |
duration | Duration DataType. |
embedding | Create an Embedding DataType: embeddings are fixed size arrays, where each element in the array has a numeric |
extension | |
fixed_size_binary | Create a FixedSizeBinary DataType: A fixed-size string of bytes. |
fixed_size_list | Create a FixedSizeList DataType: Fixed-size list, where each element in the list has type |
float32 | Create a 32-bit float DataType. |
float64 | Create a 64-bit float DataType. |
from_arrow_type | Maps a PyArrow DataType to a Daft DataType. |
from_numpy_dtype | Maps a Numpy datatype to a Daft DataType. |
image | Create an Image DataType: image arrays contain (height, width, channel) ndarrays of pixel values. |
int16 | Create an 16-bit integer DataType. |
int32 | Create an 32-bit integer DataType. |
int64 | Create an 64-bit integer DataType. |
int8 | Create an 8-bit integer DataType. |
interval | Interval DataType. |
is_binary | Check if this is a binary type. |
is_boolean | Check if this is a boolean type. |
is_date | Check if this is a date type. |
is_decimal128 | Check if this is a decimal128 type. |
is_duration | Check if this is a duration type. |
is_embedding | Check if this is an embedding type. |
is_extension | Check if this is an extension type. |
is_fixed_shape_image | Check if this is a fixed shape image type. |
is_fixed_shape_sparse_tensor | Check if this is a fixed shape sparse tensor type. |
is_fixed_shape_tensor | Check if this is a fixed shape tensor type. |
is_fixed_size_binary | Check if this is a fixed size binary type. |
is_fixed_size_list | Check if this is a fixed size list type. |
is_float32 | Check if this is a 32-bit float type. |
is_float64 | Check if this is a 64-bit float type. |
is_image | Check if this is an image type. |
is_int16 | Check if this is a 16-bit integer type. |
is_int32 | Check if this is a 32-bit integer type. |
is_int64 | Check if this is a 64-bit integer type. |
is_int8 | Check if this is an 8-bit integer type. |
is_integer | Check if this is an integer type. |
is_interval | Check if this is an interval type. |
is_list | Check if this is a list type. |
is_logical | Check if this is a logical type. |
is_map | Check if this is a map type. |
is_null | Check if this is a null type. |
is_numeric | Check if this is a numeric type. |
is_python | Check if this is a python object type. |
is_sparse_tensor | Check if this is a sparse tensor type. |
is_string | Check if this is a string type. |
is_struct | Check if this is a struct type. |
is_temporal | Check if this is a temporal type. |
is_tensor | Check if this is a tensor type. |
is_time | Check if this is a time type. |
is_timestamp | Check if this is a timestamp type. |
is_uint16 | Check if this is an unsigned 16-bit integer type. |
is_uint32 | Check if this is an unsigned 32-bit integer type. |
is_uint64 | Check if this is an unsigned 64-bit integer type. |
is_uint8 | Check if this is an unsigned 8-bit integer type. |
list | Create a List DataType: Variable-length list, where each element in the list has type |
map | Create a Map DataType: A map is a nested type of key-value pairs that is implemented as a list of structs with two fields, key and value. |
null | Creates the Null DataType: Always the |
python | Create a Python DataType: a type which refers to an arbitrary Python object. |
sparse_tensor | Create a SparseTensor DataType: SparseTensor arrays implemented as 'COO Sparse Tensor' representation of n-dimensional arrays of data of the provided |
string | Create a String DataType: A string of UTF8 characters. |
struct | Create a Struct DataType: a nested type which has names mapped to child types. |
tensor | Create a tensor DataType: tensor arrays contain n-dimensional arrays of data of the provided |
time | Time DataType. Supported timeunits are "us", "ns". |
timestamp | Timestamp DataType. |
to_arrow_dtype | |
uint16 | Create an unsigned 16-bit integer DataType. |
uint32 | Create an unsigned 32-bit integer DataType. |
uint64 | Create an unsigned 64-bit integer DataType. |
uint8 | Create an unsigned 8-bit integer DataType. |
Attributes:
Name | Type | Description |
---|---|---|
dtype | DataType | If the datatype contains an inner type, return the inner type, otherwise an attribute error is raised. |
fields | dict[str, DataType] | If this is a struct type, return the fields, otherwise an attribute error is raised. |
image_mode | ImageMode | None | If this is an image type, return the (optional) image mode, otherwise an attribute error is raised. |
key_type | DataType | If this is a map type, return the key type, otherwise an attribute error is raised. |
precision | int | If this is a decimal type, return the precision, otherwise an attribute error is raised. |
scale | int | If this is a decimal type, return the scale, otherwise an attribute error is raised. |
shape | tuple[int, ...] | If this is a fixed shape type, return the shape, otherwise an attribute error is raised. |
size | int | If this is a fixed size type, return the size, otherwise an attribute error is raised. |
timeunit | TimeUnit | If this is a time or timestamp type, return the timeunit, otherwise an attribute error is raised. |
timezone | str | None | If this is a timestamp type, return the timezone, otherwise an attribute error is raised. |
use_offset_indices | bool | If this is a sparse tensor type, return whether the indices are stored as offsets, otherwise an attribute error is raised. |
value_type | DataType | If this is a map type, return the value type, otherwise an attribute error is raised. |
Source code in daft/datatype.py
95 96 97 98 99 |
|
dtype #
dtype: DataType
If the datatype contains an inner type, return the inner type, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
fields #
fields: dict[str, DataType]
If this is a struct type, return the fields, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 9 |
|
image_mode #
image_mode: ImageMode | None
If this is an image type, return the (optional) image mode, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
key_type #
key_type: DataType
If this is a map type, return the key type, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
precision #
precision: int
If this is a decimal type, return the precision, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
scale #
scale: int
If this is a decimal type, return the scale, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
shape #
shape: tuple[int, ...]
If this is a fixed shape type, return the shape, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
size #
size: int
If this is a fixed size type, return the size, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
timeunit #
timeunit: TimeUnit
If this is a time or timestamp type, return the timeunit, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 9 |
|
timezone #
timezone: str | None
If this is a timestamp type, return the timezone, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
use_offset_indices #
use_offset_indices: bool
If this is a sparse tensor type, return whether the indices are stored as offsets, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
value_type #
value_type: DataType
If this is a map type, return the value type, otherwise an attribute error is raised.
Examples:
1 2 3 4 5 6 7 8 |
|
binary #
binary() -> DataType
Create a Binary DataType: A string of bytes.
Source code in daft/datatype.py
201 202 203 204 |
|
bool #
bool() -> DataType
Create the Boolean DataType: Either True
or False
.
Source code in daft/datatype.py
196 197 198 199 |
|
date #
date() -> DataType
Create a Date DataType: A date with a year, month and day.
Source code in daft/datatype.py
223 224 225 226 |
|
decimal128 #
decimal128(precision: int, scale: int) -> DataType
Fixed-precision decimal.
Source code in daft/datatype.py
218 219 220 221 |
|
duration #
duration(timeunit: TimeUnit | str) -> DataType
Duration DataType.
Source code in daft/datatype.py
242 243 244 245 246 247 |
|
embedding #
Create an Embedding DataType: embeddings are fixed size arrays, where each element in the array has a numeric dtype
and each array has a fixed length of size
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype | DataType | DataType of each element in the list (must be numeric) | required |
size | int | length of each list | required |
Source code in daft/datatype.py
301 302 303 304 305 306 307 308 309 310 311 |
|
extension #
Source code in daft/datatype.py
297 298 299 |
|
fixed_size_binary #
fixed_size_binary(size: int) -> DataType
Create a FixedSizeBinary DataType: A fixed-size string of bytes.
Source code in daft/datatype.py
206 207 208 209 210 211 |
|
fixed_size_list #
Create a FixedSizeList DataType: Fixed-size list, where each element in the list has type dtype
and each list has length size
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype | DataType | DataType of each element in the list | required |
size | int | length of each list | required |
Source code in daft/datatype.py
263 264 265 266 267 268 269 270 271 272 273 |
|
float32 #
float32() -> DataType
Create a 32-bit float DataType.
Source code in daft/datatype.py
181 182 183 184 |
|
float64 #
float64() -> DataType
Create a 64-bit float DataType.
Source code in daft/datatype.py
186 187 188 189 |
|
from_arrow_type #
from_arrow_type(arrow_type: DataType) -> DataType
Maps a PyArrow DataType to a Daft DataType.
Source code in daft/datatype.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
from_numpy_dtype #
from_numpy_dtype(np_type: dtype[Any]) -> DataType
Maps a Numpy datatype to a Daft DataType.
Source code in daft/datatype.py
517 518 519 520 521 |
|
image #
image(
mode: str | ImageMode | None = None,
height: int | None = None,
width: int | None = None,
) -> DataType
Create an Image DataType: image arrays contain (height, width, channel) ndarrays of pixel values.
Each image in the array has an :class:~daft.ImageMode
, which describes the pixel dtype (e.g. uint8) and the number of image channels/bands and their logical interpretation (e.g. RGB).
If the height, width, and mode are the same for all images in the array, specifying them when constructing this type is advised, since that will allow Daft to create a more optimized physical representation of the image array.
If the height, width, or mode may vary across images in the array, leaving these fields unspecified when creating this type will cause Daft to represent this image array as a heterogeneous collection of images, where each image can have a different mode, height, and width. This is much more flexible, but will result in a less compact representation and may be make some operations less efficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode | str | ImageMode | None | The mode of the image. By default, this is inferred from the underlying data. If height and width are specified, the mode must also be specified. | None |
height | int | None | The height of the image. By default, this is inferred from the underlying data. Must be specified if the width is specified. | None |
width | int | None | The width of the image. By default, this is inferred from the underlying data. Must be specified if the width is specified. | None |
Source code in daft/datatype.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
int16 #
int16() -> DataType
Create an 16-bit integer DataType.
Source code in daft/datatype.py
146 147 148 149 |
|
int32 #
int32() -> DataType
Create an 32-bit integer DataType.
Source code in daft/datatype.py
151 152 153 154 |
|
int64 #
int64() -> DataType
Create an 64-bit integer DataType.
Source code in daft/datatype.py
156 157 158 159 |
|
int8 #
int8() -> DataType
Create an 8-bit integer DataType.
Source code in daft/datatype.py
141 142 143 144 |
|
interval #
interval() -> DataType
Interval DataType.
Source code in daft/datatype.py
249 250 251 252 |
|
is_binary #
is_binary() -> bool
Check if this is a binary type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
712 713 714 715 716 717 718 719 720 |
|
is_boolean #
is_boolean() -> bool
Check if this is a boolean type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
542 543 544 545 546 547 548 549 550 |
|
is_date #
is_date() -> bool
Check if this is a date type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
672 673 674 675 676 677 678 679 680 |
|
is_decimal128 #
is_decimal128() -> bool
Check if this is a decimal128 type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
652 653 654 655 656 657 658 659 660 |
|
is_duration #
is_duration() -> bool
Check if this is a duration type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
692 693 694 695 696 697 698 699 700 |
|
is_embedding #
is_embedding() -> bool
Check if this is an embedding type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
812 813 814 815 816 817 818 819 820 |
|
is_extension #
is_extension() -> bool
Check if this is an extension type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
782 783 784 785 786 787 788 789 790 |
|
is_fixed_shape_image #
is_fixed_shape_image() -> bool
Check if this is a fixed shape image type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
802 803 804 805 806 807 808 809 810 |
|
is_fixed_shape_sparse_tensor #
is_fixed_shape_sparse_tensor() -> bool
Check if this is a fixed shape sparse tensor type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
852 853 854 855 856 857 858 859 860 |
|
is_fixed_shape_tensor #
is_fixed_shape_tensor() -> bool
Check if this is a fixed shape tensor type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
832 833 834 835 836 837 838 839 840 |
|
is_fixed_size_binary #
is_fixed_size_binary() -> bool
Check if this is a fixed size binary type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
722 723 724 725 726 727 728 729 730 |
|
is_fixed_size_list #
is_fixed_size_list() -> bool
Check if this is a fixed size list type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
752 753 754 755 756 757 758 759 760 |
|
is_float32 #
is_float32() -> bool
Check if this is a 32-bit float type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
632 633 634 635 636 637 638 639 640 |
|
is_float64 #
is_float64() -> bool
Check if this is a 64-bit float type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
642 643 644 645 646 647 648 649 650 |
|
is_image #
is_image() -> bool
Check if this is an image type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
792 793 794 795 796 797 798 799 800 |
|
is_int16 #
is_int16() -> bool
Check if this is a 16-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
562 563 564 565 566 567 568 569 570 |
|
is_int32 #
is_int32() -> bool
Check if this is a 32-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
572 573 574 575 576 577 578 579 580 |
|
is_int64 #
is_int64() -> bool
Check if this is a 64-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
582 583 584 585 586 587 588 589 590 |
|
is_int8 #
is_int8() -> bool
Check if this is an 8-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
552 553 554 555 556 557 558 559 560 |
|
is_integer #
is_integer() -> bool
Check if this is an integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
882 883 884 885 886 887 888 889 890 |
|
is_interval #
is_interval() -> bool
Check if this is an interval type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
702 703 704 705 706 707 708 709 710 |
|
is_list #
is_list() -> bool
Check if this is a list type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
742 743 744 745 746 747 748 749 750 |
|
is_logical #
is_logical() -> bool
Check if this is a logical type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
892 893 894 895 896 897 898 899 900 |
|
is_map #
is_map() -> bool
Check if this is a map type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
772 773 774 775 776 777 778 779 780 |
|
is_null #
is_null() -> bool
Check if this is a null type.
Examples:
1 2 3 4 |
|
Source code in daft/datatype.py
531 532 533 534 535 536 537 538 539 540 |
|
is_numeric #
is_numeric() -> bool
Check if this is a numeric type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
872 873 874 875 876 877 878 879 880 |
|
is_python #
is_python() -> bool
Check if this is a python object type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
862 863 864 865 866 867 868 869 870 |
|
is_sparse_tensor #
is_sparse_tensor() -> bool
Check if this is a sparse tensor type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
842 843 844 845 846 847 848 849 850 |
|
is_string #
is_string() -> bool
Check if this is a string type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
732 733 734 735 736 737 738 739 740 |
|
is_struct #
is_struct() -> bool
Check if this is a struct type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
762 763 764 765 766 767 768 769 770 |
|
is_temporal #
is_temporal() -> bool
Check if this is a temporal type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
902 903 904 905 906 907 908 909 910 |
|
is_tensor #
is_tensor() -> bool
Check if this is a tensor type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
822 823 824 825 826 827 828 829 830 |
|
is_time #
is_time() -> bool
Check if this is a time type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
682 683 684 685 686 687 688 689 690 |
|
is_timestamp #
is_timestamp() -> bool
Check if this is a timestamp type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
662 663 664 665 666 667 668 669 670 |
|
is_uint16 #
is_uint16() -> bool
Check if this is an unsigned 16-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
602 603 604 605 606 607 608 609 610 |
|
is_uint32 #
is_uint32() -> bool
Check if this is an unsigned 32-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
612 613 614 615 616 617 618 619 620 |
|
is_uint64 #
is_uint64() -> bool
Check if this is an unsigned 64-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
622 623 624 625 626 627 628 629 630 |
|
is_uint8 #
is_uint8() -> bool
Check if this is an unsigned 8-bit integer type.
Examples:
1 2 3 |
|
Source code in daft/datatype.py
592 593 594 595 596 597 598 599 600 |
|
list #
Create a List DataType: Variable-length list, where each element in the list has type dtype
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype | DataType | DataType of each element in the list | required |
Source code in daft/datatype.py
254 255 256 257 258 259 260 261 |
|
map #
Create a Map DataType: A map is a nested type of key-value pairs that is implemented as a list of structs with two fields, key and value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_type | DataType | DataType of the keys in the map | required |
value_type | DataType | DataType of the values in the map | required |
Source code in daft/datatype.py
275 276 277 278 279 280 281 282 283 |
|
null #
null() -> DataType
Creates the Null DataType: Always the Null
value.
Source code in daft/datatype.py
213 214 215 216 |
|
python #
python() -> DataType
Create a Python DataType: a type which refers to an arbitrary Python object.
Source code in daft/datatype.py
526 527 528 529 |
|
sparse_tensor #
sparse_tensor(
dtype: DataType,
shape: tuple[int, ...] | None = None,
use_offset_indices: bool = False,
) -> DataType
Create a SparseTensor DataType: SparseTensor arrays implemented as 'COO Sparse Tensor' representation of n-dimensional arrays of data of the provided dtype
as elements, each of the provided shape
.
If a shape
is given, each ndarray in the column will have this shape.
If shape
is not given, the ndarrays in the column can have different shapes. This is much more flexible, but will result in a less compact representation and may be make some operations less efficient.
The use_offset_indices
parameter determines how the indices of the SparseTensor are stored: - False
(default): Indices represent the actual positions of nonzero values. - True
: Indices represent the offsets between consecutive nonzero values. This can improve compression efficiency, especially when nonzero values are clustered together, as offsets between them are often zero, making them easier to compress.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype | DataType | The type of the data contained within the tensor elements. | required |
shape | tuple[int, ...] | None | The shape of each SparseTensor in the column. This is | None |
use_offset_indices | bool | Determines how indices are represented. Defaults to | False |
Source code in daft/datatype.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
string #
string() -> DataType
Create a String DataType: A string of UTF8 characters.
Source code in daft/datatype.py
191 192 193 194 |
|
struct #
Create a Struct DataType: a nested type which has names mapped to child types.
Examples:
1 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields | dict[str, DataType] | Nested fields of the Struct | required |
Source code in daft/datatype.py
285 286 287 288 289 290 291 292 293 294 295 |
|
tensor #
Create a tensor DataType: tensor arrays contain n-dimensional arrays of data of the provided dtype
as elements, each of the provided shape
.
If a shape
is given, each ndarray in the column will have this shape.
If shape
is not given, the ndarrays in the column can have different shapes. This is much more flexible, but will result in a less compact representation and may be make some operations less efficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype | DataType | The type of the data contained within the tensor elements. | required |
shape | tuple[int, ...] | None | The shape of each tensor in the column. This is | None |
Source code in daft/datatype.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
time #
time(timeunit: TimeUnit | str) -> DataType
Time DataType. Supported timeunits are "us", "ns".
Source code in daft/datatype.py
228 229 230 231 232 233 |
|
timestamp #
timestamp(
timeunit: TimeUnit | str, timezone: str | None = None
) -> DataType
Timestamp DataType.
Source code in daft/datatype.py
235 236 237 238 239 240 |
|
to_arrow_dtype #
to_arrow_dtype() -> DataType
Source code in daft/datatype.py
523 524 |
|
uint16 #
uint16() -> DataType
Create an unsigned 16-bit integer DataType.
Source code in daft/datatype.py
166 167 168 169 |
|
uint32 #
uint32() -> DataType
Create an unsigned 32-bit integer DataType.
Source code in daft/datatype.py
171 172 173 174 |
|