@@ -209,7 +209,7 @@ def shape(self) -> typing.Tuple[int, int]:
209209 except Exception :
210210 pass
211211
212- iter , _ = self .session ._execute (row_count_expr , sorted = False )
212+ iter , _ = self .session ._execute (row_count_expr , ordered = False )
213213 row_count = next (iter )[0 ]
214214 return (row_count , len (self .value_columns ))
215215
@@ -518,7 +518,7 @@ def to_pandas_batches(
518518 dtypes = dict (zip (self .index_columns , self .index .dtypes ))
519519 dtypes .update (zip (self .value_columns , self .dtypes ))
520520 _ , query_job = self .session ._query_to_destination (
521- self .session ._to_sql (self .expr , sorted = True ),
521+ self .session ._to_sql (self .expr , ordered = self . session . _strictly_ordered ),
522522 list (self .index_columns ),
523523 api_name = "cached" ,
524524 do_clustering = False ,
@@ -553,7 +553,7 @@ def _materialize_local(
553553 """Run query and download results as a pandas DataFrame. Return the total number of results as well."""
554554 # TODO(swast): Allow for dry run and timeout.
555555 _ , query_job = self .session ._query_to_destination (
556- self .session ._to_sql (self .expr , sorted = materialize_options .ordered ),
556+ self .session ._to_sql (self .expr , ordered = materialize_options .ordered ),
557557 list (self .index_columns ),
558558 api_name = "cached" ,
559559 do_clustering = False ,
@@ -1736,7 +1736,7 @@ def transpose(
17361736 original_row_index = (
17371737 original_row_index
17381738 if original_row_index is not None
1739- else self .index .to_pandas ()
1739+ else self .index .to_pandas (ordered = True )
17401740 )
17411741 original_row_count = len (original_row_index )
17421742 if original_row_count > bigframes .constants .MAX_COLUMNS :
@@ -2507,7 +2507,7 @@ def column_ids(self) -> Sequence[str]:
25072507 """Column(s) to use as row labels."""
25082508 return self ._block ._index_columns
25092509
2510- def to_pandas (self ) -> pd .Index :
2510+ def to_pandas (self , * , ordered : Optional [ bool ] = None ) -> pd .Index :
25112511 """Executes deferred operations and downloads the results."""
25122512 if len (self .column_ids ) == 0 :
25132513 raise bigframes .exceptions .NullIndexError (
@@ -2517,7 +2517,12 @@ def to_pandas(self) -> pd.Index:
25172517 index_columns = list (self ._block .index_columns )
25182518 dtypes = dict (zip (index_columns , self .dtypes ))
25192519 expr = self ._expr .select_columns (index_columns )
2520- results , _ = self .session ._execute (expr )
2520+ results , _ = self .session ._execute (
2521+ expr ,
2522+ ordered = ordered
2523+ if (ordered is not None )
2524+ else self .session ._strictly_ordered ,
2525+ )
25212526 df = expr .session ._rows_to_dataframe (results , dtypes )
25222527 df = df .set_index (index_columns )
25232528 index = df .index
0 commit comments