Skip to content
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

feat: Add transpose support for small homogeneously typed DataFrames. #621

Merged
merged 4 commits into from
Apr 23, 2024

Conversation

TrevorBergeron
Copy link
Contributor

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 #<issue_number_goes_here> 🦕

@TrevorBergeron TrevorBergeron requested review from a team as code owners April 18, 2024 00:54
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Apr 18, 2024
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. label Apr 18, 2024
@TrevorBergeron TrevorBergeron requested review from milkshakeiii and removed request for chelsea-lin April 18, 2024 19:29
Copy link
Contributor

@milkshakeiii milkshakeiii left a comment

Choose a reason for hiding this comment

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

LGTM, just suggested we make it more clear in the docstrings exactly what the dtype restriction is.


Reflect the DataFrame over its main diagonal by writing rows as columns
and vice-versa. The property :attr:`.T` is an accessor to the method
:meth:`transpose`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add something here about the dtypes requirements? (Columns must be coerceable to a common type) (I know it's below but seems important enough to be up top.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -2465,6 +2465,24 @@ def test_df_describe(scalars_dfs):
).all()


def test_df_transpose():
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a cheap test, we could add a check that we raise TypeError for mixing strs and floats.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -1570,6 +1575,52 @@ def melt(
index_columns=[index_id],
)

def transpose(self) -> Block:
"""Transpose the block. Will fail if dtypes incompatible or too many rows"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest we change "dtypes incompatible" to "dtypes cannot be coerced all to a common type."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@TrevorBergeron TrevorBergeron enabled auto-merge (squash) April 23, 2024 00:07
@TrevorBergeron TrevorBergeron merged commit 054075d into main Apr 23, 2024
15 of 16 checks passed
@TrevorBergeron TrevorBergeron deleted the transpose3 branch April 23, 2024 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants