Skip to content

Commit b1215ca

Browse files
committed
Merge branch 'main' into shuowei-time-series-bike
2 parents 85b99b3 + f0ed9bc commit b1215ca

File tree

9 files changed

+330
-146
lines changed

9 files changed

+330
-146
lines changed

bigframes/display/anywidget.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _cached_data(self) -> pd.DataFrame:
245245
"""Combine all cached batches into a single DataFrame."""
246246
if not self._cached_batches:
247247
return pd.DataFrame(columns=self._dataframe.columns)
248-
return pd.concat(self._cached_batches, ignore_index=True)
248+
return pd.concat(self._cached_batches)
249249

250250
def _reset_batch_cache(self) -> None:
251251
"""Resets batch caching attributes."""
@@ -294,8 +294,18 @@ def _set_table_html(self) -> None:
294294
break
295295

296296
# Get the data for the current page
297-
page_data = cached_data.iloc[start:end]
298-
297+
page_data = cached_data.iloc[start:end].copy()
298+
299+
# Handle index display
300+
# TODO(b/438181139): Add tests for custom multiindex
301+
if self._dataframe._block.has_index:
302+
index_name = page_data.index.name
303+
page_data.insert(
304+
0, index_name if index_name is not None else "", page_data.index
305+
)
306+
else:
307+
# Default index - include as "Row" column
308+
page_data.insert(0, "Row", range(start + 1, start + len(page_data) + 1))
299309
# Handle case where user navigated beyond available data with unknown row count
300310
is_unknown_count = self.row_count is None
301311
is_beyond_data = self._all_data_loaded and len(page_data) == 0 and self.page > 0

bigframes/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ def to_dict(
23032303
*,
23042304
allow_large_results: Optional[bool] = None,
23052305
) -> typing.Mapping:
2306-
return typing.cast(dict, self.to_pandas(allow_large_results=allow_large_results).to_dict(into)) # type: ignore
2306+
return typing.cast(dict, self.to_pandas(allow_large_results=allow_large_results).to_dict(into=into)) # type: ignore
23072307

23082308
def to_excel(
23092309
self, excel_writer, sheet_name="Sheet1", *, allow_large_results=None, **kwargs

bigframes/testing/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import base64
1616
import decimal
17+
import re
1718
from typing import Iterable, Optional, Sequence, Set, Union
1819

1920
import geopandas as gpd # type: ignore
@@ -69,6 +70,12 @@
6970
]
7071

7172

73+
def pandas_major_version() -> int:
74+
match = re.search(r"^v?(\d+)", pd.__version__.strip())
75+
assert match is not None
76+
return int(match.group(1))
77+
78+
7279
# Prefer this function for tests that run in both ordered and unordered mode
7380
def assert_dfs_equivalent(pd_df: pd.DataFrame, bf_df: bpd.DataFrame, **kwargs):
7481
bf_df_local = bf_df.to_pandas()
@@ -83,7 +90,7 @@ def assert_series_equivalent(pd_series: pd.Series, bf_series: bpd.Series, **kwar
8390

8491

8592
def _normalize_all_nulls(col: pd.Series) -> pd.Series:
86-
if col.dtype == bigframes.dtypes.FLOAT_DTYPE:
93+
if col.dtype in (bigframes.dtypes.FLOAT_DTYPE, bigframes.dtypes.INT_DTYPE):
8794
col = col.astype("float64")
8895
if pd_types.is_object_dtype(col):
8996
col = col.fillna(float("nan"))
@@ -134,6 +141,15 @@ def assert_series_equal(
134141
left = left.sort_index()
135142
right = right.sort_index()
136143

144+
if isinstance(left.index, pd.RangeIndex) or pd_types.is_integer_dtype(
145+
left.index.dtype,
146+
):
147+
left.index = left.index.astype("Int64")
148+
if isinstance(right.index, pd.RangeIndex) or pd_types.is_integer_dtype(
149+
right.index.dtype,
150+
):
151+
right.index = right.index.astype("Int64")
152+
137153
if nulls_are_nan:
138154
left = _normalize_all_nulls(left)
139155
right = _normalize_all_nulls(right)

0 commit comments

Comments
 (0)