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

Raise ValueError if DataFrame column length does not match data #14135

Closed

Conversation

mroeschke
Copy link
Contributor

Description

closes #14131

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mroeschke mroeschke added bug Something isn't working Python Affects Python cuDF API. non-breaking Non-breaking change labels Sep 20, 2023
@mroeschke mroeschke requested a review from a team as a code owner September 20, 2023 01:34
@davidwendt
Copy link
Contributor

Is the PR title missing a not ?

@mroeschke mroeschke changed the title Raise ValueError if DataFrame column length does match data Raise ValueError if DataFrame column length does not match data Sep 21, 2023
@mroeschke
Copy link
Contributor Author

Is the PR title missing a not ?

Yes, thanks!

@mroeschke
Copy link
Contributor Author

cc @galipremsagar if you have a moment to review

@@ -645,7 +645,15 @@ def __init__(
elif isinstance(data, (cudf.Series, pd.Series)):
if isinstance(data, pd.Series):
data = cudf.Series.from_pandas(data, nan_as_null=nan_as_null)

if (
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we shouldn't be raising no?:

In [1]: import pandas as pd

In [2]: s = pd.Series([1, 2, 3], name=2)

In [3]: pd.DataFrame(s)
Out[3]: 
   2
0  1
1  2
2  3

In [4]: pd.DataFrame(s, columns=[])
Out[4]: 
Empty DataFrame
Columns: []
Index: []

In [5]: pd.DataFrame(s, columns=[2])
Out[5]: 
   2
0  1
1  2
2  3

In [6]: pd.DataFrame(s, columns=[2, 1])
Out[6]: 
   2    1
0  1  NaN
1  2  NaN
2  3  NaN

In [7]: pd.DataFrame(s, columns=[1])
Out[7]: 
Empty DataFrame
Columns: [1]
Index: []

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I guess it's this very narrow use case that should only raise. (I'm not sure of the history why the other cases are allowed)

@mroeschke mroeschke closed this Oct 10, 2023
@mroeschke mroeschke deleted the bug/df/column_mismatch branch October 10, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] DataFrame allows Series input with len(columns) > 1
3 participants