@@ -205,93 +205,100 @@ class SimpleDtypeInfo:
205205
206206
207207## dtype predicates - use these to maintain consistency
208- def is_datetime_like (type : ExpressionType ) -> bool :
209- return type in (DATETIME_DTYPE , TIMESTAMP_DTYPE )
208+ def is_datetime_like (type_ : ExpressionType ) -> bool :
209+ return type_ in (DATETIME_DTYPE , TIMESTAMP_DTYPE )
210210
211211
212- def is_date_like (type : ExpressionType ) -> bool :
213- return type in (DATETIME_DTYPE , TIMESTAMP_DTYPE , DATE_DTYPE )
212+ def is_date_like (type_ : ExpressionType ) -> bool :
213+ return type_ in (DATETIME_DTYPE , TIMESTAMP_DTYPE , DATE_DTYPE )
214214
215215
216- def is_time_like (type : ExpressionType ) -> bool :
217- return type in (DATETIME_DTYPE , TIMESTAMP_DTYPE , TIME_DTYPE )
216+ def is_time_like (type_ : ExpressionType ) -> bool :
217+ return type_ in (DATETIME_DTYPE , TIMESTAMP_DTYPE , TIME_DTYPE )
218218
219219
220- def is_binary_like (type : ExpressionType ) -> bool :
221- return type in (BOOL_DTYPE , BYTES_DTYPE , INT_DTYPE )
220+ def is_binary_like (type_ : ExpressionType ) -> bool :
221+ return type_ in (BOOL_DTYPE , BYTES_DTYPE , INT_DTYPE )
222222
223223
224- def is_string_like (type : ExpressionType ) -> bool :
225- return type in (STRING_DTYPE , BYTES_DTYPE )
224+ def is_object_like (type_ : Union [ExpressionType , str ]) -> bool :
225+ # See: https://stackoverflow.com/a/40312924/101923 and
226+ # https://numpy.org/doc/stable/reference/generated/numpy.dtype.kind.html
227+ # for the way to identify object type.
228+ return type_ in ("object" , "O" ) or getattr (type_ , "kind" , None ) == "O"
226229
227230
228- def is_array_like (type : ExpressionType ) -> bool :
229- return isinstance (type , pd .ArrowDtype ) and isinstance (
230- type .pyarrow_dtype , pa .ListType
231+ def is_string_like (type_ : ExpressionType ) -> bool :
232+ return type_ in (STRING_DTYPE , BYTES_DTYPE )
233+
234+
235+ def is_array_like (type_ : ExpressionType ) -> bool :
236+ return isinstance (type_ , pd .ArrowDtype ) and isinstance (
237+ type_ .pyarrow_dtype , pa .ListType
231238 )
232239
233240
234- def is_array_string_like (type : ExpressionType ) -> bool :
241+ def is_array_string_like (type_ : ExpressionType ) -> bool :
235242 return (
236- isinstance (type , pd .ArrowDtype )
237- and isinstance (type .pyarrow_dtype , pa .ListType )
238- and pa .types .is_string (type .pyarrow_dtype .value_type )
243+ isinstance (type_ , pd .ArrowDtype )
244+ and isinstance (type_ .pyarrow_dtype , pa .ListType )
245+ and pa .types .is_string (type_ .pyarrow_dtype .value_type )
239246 )
240247
241248
242- def is_struct_like (type : ExpressionType ) -> bool :
243- return isinstance (type , pd .ArrowDtype ) and isinstance (
244- type .pyarrow_dtype , pa .StructType
249+ def is_struct_like (type_ : ExpressionType ) -> bool :
250+ return isinstance (type_ , pd .ArrowDtype ) and isinstance (
251+ type_ .pyarrow_dtype , pa .StructType
245252 )
246253
247254
248- def is_json_like (type : ExpressionType ) -> bool :
255+ def is_json_like (type_ : ExpressionType ) -> bool :
249256 # TODO: Add JSON type support
250- return type == STRING_DTYPE
257+ return type_ == STRING_DTYPE
251258
252259
253- def is_json_encoding_type (type : ExpressionType ) -> bool :
260+ def is_json_encoding_type (type_ : ExpressionType ) -> bool :
254261 # Types can be converted into JSON.
255262 # https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions#json_encodings
256- return type != GEO_DTYPE
263+ return type_ != GEO_DTYPE
257264
258265
259- def is_numeric (type : ExpressionType ) -> bool :
260- return type in NUMERIC_BIGFRAMES_TYPES_PERMISSIVE
266+ def is_numeric (type_ : ExpressionType ) -> bool :
267+ return type_ in NUMERIC_BIGFRAMES_TYPES_PERMISSIVE
261268
262269
263- def is_iterable (type : ExpressionType ) -> bool :
264- return type in (STRING_DTYPE , BYTES_DTYPE ) or is_array_like (type )
270+ def is_iterable (type_ : ExpressionType ) -> bool :
271+ return type_ in (STRING_DTYPE , BYTES_DTYPE ) or is_array_like (type_ )
265272
266273
267- def is_comparable (type : ExpressionType ) -> bool :
268- return (type is not None ) and is_orderable (type )
274+ def is_comparable (type_ : ExpressionType ) -> bool :
275+ return (type_ is not None ) and is_orderable (type_ )
269276
270277
271278_ORDERABLE_SIMPLE_TYPES = set (
272279 mapping .dtype for mapping in SIMPLE_TYPES if mapping .orderable
273280)
274281
275282
276- def is_orderable (type : ExpressionType ) -> bool :
283+ def is_orderable (type_ : ExpressionType ) -> bool :
277284 # On BQ side, ARRAY, STRUCT, GEOGRAPHY, JSON are not orderable
278- return type in _ORDERABLE_SIMPLE_TYPES
285+ return type_ in _ORDERABLE_SIMPLE_TYPES
279286
280287
281288_CLUSTERABLE_SIMPLE_TYPES = set (
282289 mapping .dtype for mapping in SIMPLE_TYPES if mapping .clusterable
283290)
284291
285292
286- def is_clusterable (type : ExpressionType ) -> bool :
293+ def is_clusterable (type_ : ExpressionType ) -> bool :
287294 # https://cloud.google.com/bigquery/docs/clustered-tables#cluster_column_types
288295 # This is based on default database type mapping, could in theory represent in non-default bq type to cluster.
289- return type in _CLUSTERABLE_SIMPLE_TYPES
296+ return type_ in _CLUSTERABLE_SIMPLE_TYPES
290297
291298
292- def is_bool_coercable (type : ExpressionType ) -> bool :
299+ def is_bool_coercable (type_ : ExpressionType ) -> bool :
293300 # TODO: Implement more bool coercions
294- return (type is None ) or is_numeric (type ) or is_string_like (type )
301+ return (type_ is None ) or is_numeric (type_ ) or is_string_like (type_ )
295302
296303
297304BIGFRAMES_STRING_TO_BIGFRAMES : Dict [DtypeString , Dtype ] = {
0 commit comments