Skip to content

fix: Fix Series.to_frame generating string label instead of int where… #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bigframes/core/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def _perform_loc_list_join(
if isinstance(series_or_dataframe, bigframes.series.Series):
_struct_accessor_check_and_warn(series_or_dataframe, keys_index)
original_name = series_or_dataframe.name
name = series_or_dataframe.name if series_or_dataframe.name is not None else "0"
name = series_or_dataframe.name if series_or_dataframe.name is not None else 0
result = typing.cast(
bigframes.series.Series,
series_or_dataframe.to_frame()._perform_join_by_index(
Expand Down Expand Up @@ -468,7 +468,7 @@ def _iloc_getitem_series_or_dataframe(
if isinstance(series_or_dataframe, bigframes.series.Series):
original_series_name = series_or_dataframe.name
series_name = (
original_series_name if original_series_name is not None else "0"
original_series_name if original_series_name is not None else 0
)
df = series_or_dataframe.to_frame()
original_index_names = df.index.names
Expand Down
2 changes: 1 addition & 1 deletion bigframes/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ def to_frame(self, name: blocks.Label = None) -> bigframes.dataframe.DataFrame:
provided_name = name if name else self.name
# To be consistent with Pandas, it assigns 0 as the column name if missing. 0 is the first element of RangeIndex.
block = self._block.with_column_labels(
[provided_name] if provided_name else ["0"]
[provided_name] if provided_name else [0]
)
return bigframes.dataframe.DataFrame(block)

Expand Down
2 changes: 1 addition & 1 deletion bigframes/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def read_pickle(

if isinstance(pandas_obj, pandas.Series):
if pandas_obj.name is None:
pandas_obj.name = "0"
pandas_obj.name = 0
bigframes_df = self._read_pandas(pandas_obj.to_frame(), "read_pickle")
return bigframes_df[bigframes_df.columns[0]]
return self._read_pandas(pandas_obj, "read_pickle")
Expand Down
9 changes: 9 additions & 0 deletions tests/system/small/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,15 @@ def test_to_frame(scalars_dfs):
assert_pandas_df_equal(bf_result, pd_result)


def test_to_frame_no_name(scalars_dfs):
scalars_df, scalars_pandas_df = scalars_dfs

bf_result = scalars_df["int64_col"].rename(None).to_frame().to_pandas()
pd_result = scalars_pandas_df["int64_col"].rename(None).to_frame()

assert_pandas_df_equal(bf_result, pd_result)


def test_to_json(gcs_folder, scalars_df_index, scalars_pandas_df_index):
path = gcs_folder + "test_series_to_json*.jsonl"
scalars_df_index["int64_col"].to_json(path, lines=True, orient="records")
Expand Down