2626from bigframes_vendored .ibis .expr .operations import window as ibis_expr_window
2727import bigframes_vendored .ibis .expr .operations as ibis_ops
2828import bigframes_vendored .ibis .expr .types as ibis_types
29- import pandas
29+ from google .cloud import bigquery
30+ import pyarrow as pa
3031
3132import bigframes .core .compile .aggregate_compiler as agg_compiler
3233import bigframes .core .compile .googlesql
3334import bigframes .core .compile .ibis_types
3435import bigframes .core .compile .scalar_op_compiler as op_compilers
3536import bigframes .core .compile .scalar_op_compiler as scalar_op_compiler
3637import bigframes .core .expression as ex
37- import bigframes .core .guid
3838from bigframes .core .ordering import OrderingExpression
3939import bigframes .core .sql
4040from bigframes .core .window_spec import RangeWindowBounds , RowsWindowBounds , WindowSpec
@@ -279,11 +279,8 @@ def _reproject_to_table(self) -> UnorderedIR:
279279 )
280280
281281 @classmethod
282- def from_pandas (
283- cls ,
284- pd_df : pandas .DataFrame ,
285- scan_cols : bigframes .core .nodes .ScanList ,
286- offsets : typing .Optional [str ] = None ,
282+ def from_polars (
283+ cls , pa_table : pa .Table , schema : Sequence [bigquery .SchemaField ]
287284 ) -> UnorderedIR :
288285 # TODO: add offsets
289286 """
@@ -292,37 +289,16 @@ def from_pandas(
292289 Assumed that the dataframe has unique string column names and bigframes-suppported
293290 dtypes.
294291 """
292+ import bigframes_vendored .ibis .backends .bigquery .datatypes as third_party_ibis_bqtypes
295293
296- # ibis memtable cannot handle NA, must convert to None
297- # this destroys the schema however
298- ibis_values = pd_df .astype ("object" ).where (pandas .notnull (pd_df ), None ) # type: ignore
299- if offsets :
300- ibis_values = ibis_values .assign (** {offsets : range (len (pd_df ))})
301294 # derive the ibis schema from the original pandas schema
302- ibis_schema = [
303- (
304- local_label ,
305- bigframes .core .compile .ibis_types .bigframes_dtype_to_ibis_dtype (dtype ),
306- )
307- for id , dtype , local_label in scan_cols .items
308- ]
309- if offsets :
310- ibis_schema .append ((offsets , ibis_dtypes .int64 ))
311-
312295 keys_memtable = bigframes_vendored .ibis .memtable (
313- ibis_values , schema = bigframes_vendored .ibis .schema (ibis_schema )
296+ pa_table ,
297+ schema = third_party_ibis_bqtypes .BigQuerySchema .to_ibis (list (schema )),
314298 )
315-
316- columns = [
317- keys_memtable [local_label ].name (col_id .sql )
318- for col_id , _ , local_label in scan_cols .items
319- ]
320- if offsets :
321- columns .append (keys_memtable [offsets ].name (offsets ))
322-
323299 return cls (
324300 keys_memtable ,
325- columns = columns ,
301+ columns = tuple ( keys_memtable [ key ] for key in keys_memtable . columns ) ,
326302 )
327303
328304 def join (
0 commit comments