|
47 | 47 | # None represents the type of a None scalar.
|
48 | 48 | ExpressionType = typing.Optional[Dtype]
|
49 | 49 |
|
50 |
| -# Used when storing Null expressions |
51 |
| -DEFAULT_DTYPE = pd.Float64Dtype() |
52 | 50 |
|
53 | 51 | INT_DTYPE = pd.Int64Dtype()
|
54 | 52 | FLOAT_DTYPE = pd.Float64Dtype()
|
55 | 53 | BOOL_DTYPE = pd.BooleanDtype()
|
56 | 54 | STRING_DTYPE = pd.StringDtype(storage="pyarrow")
|
| 55 | +BYTES_DTYPE = pd.ArrowDtype(pa.binary()) |
| 56 | +DATE_DTYPE = pd.ArrowDtype(pa.date32()) |
| 57 | +TIME_DTYPE = pd.ArrowDtype(pa.time64("us")) |
| 58 | +DATETIME_DTYPE = pd.ArrowDtype(pa.timestamp("us")) |
| 59 | +TIMESTAMP_DTYPE = pd.ArrowDtype(pa.timestamp("us", tz="UTC")) |
| 60 | + |
| 61 | +# Used when storing Null expressions |
| 62 | +DEFAULT_DTYPE = FLOAT_DTYPE |
57 | 63 |
|
58 | 64 | # On BQ side, ARRAY, STRUCT, GEOGRAPHY, JSON are not orderable
|
59 | 65 | UNORDERED_DTYPES = [gpd.array.GeometryDtype()]
|
|
100 | 106 | pd.ArrowDtype(pa.decimal256(76, 38)),
|
101 | 107 | ]
|
102 | 108 |
|
| 109 | + |
| 110 | +## dtype predicates - use these to maintain consistency |
| 111 | +def is_datetime_like(type: ExpressionType) -> bool: |
| 112 | + return type in (DATETIME_DTYPE, TIMESTAMP_DTYPE) |
| 113 | + |
| 114 | + |
| 115 | +def is_date_like(type: ExpressionType) -> bool: |
| 116 | + return type in (DATETIME_DTYPE, TIMESTAMP_DTYPE, DATE_DTYPE) |
| 117 | + |
| 118 | + |
| 119 | +def is_time_like(type: ExpressionType) -> bool: |
| 120 | + return type in (DATETIME_DTYPE, TIMESTAMP_DTYPE, TIME_DTYPE) |
| 121 | + |
| 122 | + |
| 123 | +def is_binary_like(type: ExpressionType) -> bool: |
| 124 | + return type in (BOOL_DTYPE, BYTES_DTYPE, INT_DTYPE) |
| 125 | + |
| 126 | + |
| 127 | +def is_string_like(type: ExpressionType) -> bool: |
| 128 | + return type in (STRING_DTYPE, BYTES_DTYPE) |
| 129 | + |
| 130 | + |
| 131 | +def is_array_like(type: ExpressionType) -> bool: |
| 132 | + if isinstance(type, pd.ArrowDtype) and isinstance(type.pyarrow_dtype, pa.ListType): |
| 133 | + return True |
| 134 | + else: |
| 135 | + return type in (STRING_DTYPE, BYTES_DTYPE) |
| 136 | + |
| 137 | + |
| 138 | +def is_numeric(type: ExpressionType) -> bool: |
| 139 | + return type in NUMERIC_BIGFRAMES_TYPES_PERMISSIVE |
| 140 | + |
| 141 | + |
| 142 | +def is_comparable(type: ExpressionType) -> bool: |
| 143 | + return (type is not None) and (type not in UNORDERED_DTYPES) |
| 144 | + |
| 145 | + |
103 | 146 | # Type hints for Ibis data types that can be read to Python objects by BigQuery DataFrame
|
104 | 147 | ReadOnlyIbisDtype = Union[
|
105 | 148 | ibis_dtypes.Binary,
|
|
0 commit comments