Skip to content

Commit ffb4b57

Browse files
fix: Fix Null index assign series to column (#711)
1 parent e7da0f0 commit ffb4b57

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

bigframes/dataframe.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,12 @@ def memory_usage(self, index: bool = True):
400400
column_sizes = self.dtypes.map(
401401
lambda dtype: bigframes.dtypes.DTYPE_BYTE_SIZES.get(dtype, 8) * n_rows
402402
)
403-
if index:
403+
if index and self._has_index:
404404
index_size = pandas.Series([self.index._memory_usage()], index=["Index"])
405405
column_sizes = pandas.concat([index_size, column_sizes])
406406
return column_sizes
407407

408+
@requires_index
408409
def info(
409410
self,
410411
verbose: Optional[bool] = None,
@@ -768,7 +769,7 @@ def _apply_series_binop_axis_0(
768769
block = block.drop_columns([get_column_left[column_id]])
769770

770771
block = block.drop_columns([series_col])
771-
block = block.with_index_labels(self.index.names)
772+
block = block.with_index_labels(self._block.index.names)
772773
return DataFrame(block)
773774

774775
def _apply_series_binop_axis_1(
@@ -1611,7 +1612,7 @@ def _assign_series_join_on_index(
16111612
# Update case, remove after copying into columns
16121613
block = block.drop_columns([source_column])
16131614

1614-
return DataFrame(block.with_index_labels(self.index.names))
1615+
return DataFrame(block.with_index_labels(self._block.index.names))
16151616

16161617
def reset_index(self, *, drop: bool = False) -> DataFrame:
16171618
block = self._block.reset_index(drop)
@@ -3283,7 +3284,7 @@ def _prepare_export(
32833284
array_value = self._block.expr
32843285

32853286
new_col_labels, new_idx_labels = utils.get_standardized_ids(
3286-
self._block.column_labels, self.index.names
3287+
self._block.column_labels, self._block.index.names
32873288
)
32883289

32893290
columns = list(self._block.value_columns)
@@ -3320,7 +3321,7 @@ def _run_io_query(
33203321
session = self._block.expr.session
33213322
self._optimize_query_complexity()
33223323
export_array, id_overrides = self._prepare_export(
3323-
index=index, ordering_id=ordering_id
3324+
index=index and self._has_index, ordering_id=ordering_id
33243325
)
33253326

33263327
_, query_job = session._execute(

tests/system/small/test_empty_index.py

+15
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ def test_empty_index_df_self_aligns(
169169
)
170170

171171

172+
def test_empty_index_setitem(scalars_df_empty_index, scalars_pandas_df_default_index):
173+
bf_result = scalars_df_empty_index.copy()
174+
bf_result["new_col"] = (
175+
scalars_df_empty_index["int64_col"] + scalars_df_empty_index["float64_col"]
176+
)
177+
pd_result = scalars_pandas_df_default_index.copy()
178+
pd_result["new_col"] = (
179+
scalars_pandas_df_default_index["int64_col"]
180+
+ scalars_pandas_df_default_index["float64_col"]
181+
)
182+
pd.testing.assert_frame_equal(
183+
bf_result.to_pandas(), pd_result.reset_index(drop=True), check_dtype=False
184+
)
185+
186+
172187
def test_empty_index_df_concat(scalars_df_empty_index, scalars_pandas_df_default_index):
173188
bf_result = bpd.concat([scalars_df_empty_index, scalars_df_empty_index])
174189
pd_result = pd.concat(

0 commit comments

Comments
 (0)