Skip to content

fix: avoid copy argument warning in to_pandas#16917

Open
tswast wants to merge 1 commit intomainfrom
b508671576-copy-arg
Open

fix: avoid copy argument warning in to_pandas#16917
tswast wants to merge 1 commit intomainfrom
b508671576-copy-arg

Conversation

@tswast
Copy link
Copy Markdown
Contributor

@tswast tswast commented May 1, 2026

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes internal issue b/508671576 🦕

@tswast tswast requested review from a team as code owners May 1, 2026 20:17
@tswast tswast requested review from TrevorBergeron and removed request for a team May 1, 2026 20:17
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the deprecated copy parameter from set_axis calls in blocks.py and dataframe.py. Feedback suggests that instead of using set_axis, which may still perform a copy in newer Pandas versions, the code should directly assign to the .columns attribute to ensure efficiency and avoid deprecation warnings.

Comment on lines +850 to +851

df = self._copy_index_to_pandas(raw_df).set_axis(self.column_labels, axis=1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The copy parameter in set_axis is deprecated in recent Pandas versions. To avoid the warning and prevent an unnecessary full copy of the DataFrame (which set_axis performs by default in newer versions), it is recommended to assign directly to the .columns attribute. This is the official Pandas recommendation for replacing set_axis(..., copy=False) when modifying a fresh object.

Suggested change
df = self._copy_index_to_pandas(raw_df).set_axis(self.column_labels, axis=1)
df = self._copy_index_to_pandas(raw_df)
df.columns = self.column_labels

if query_job:
self._set_internal_query_job(query_job)
return df.set_axis(self._block.column_labels, axis=1, copy=False)
return df.set_axis(self._block.column_labels, axis=1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The copy parameter in set_axis is deprecated. To avoid the warning and prevent an unnecessary copy of the DataFrame, assign directly to the .columns attribute.

Suggested change
return df.set_axis(self._block.column_labels, axis=1)
df.columns = self._block.column_labels
return df

"Cannot peek efficiently when data has aggregates, joins or window functions applied. Use force=True to fully compute dataframe."
)
return maybe_result.set_axis(self._block.column_labels, axis=1, copy=False)
return maybe_result.set_axis(self._block.column_labels, axis=1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The copy parameter in set_axis is deprecated. To avoid the warning and prevent an unnecessary copy of the DataFrame, assign directly to the .columns attribute.

Suggested change
return maybe_result.set_axis(self._block.column_labels, axis=1)
maybe_result.columns = self._block.column_labels
return maybe_result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant