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(python): Add default to_struct Series name consistent with the usual default Series name (empty string) #12998

Merged

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Dec 11, 2023

Closes #12947.

Seems reasonable to be consistent here; the standard behaviour when creating a Series directly (without giving it an explicit name) is to assign the default name as the empty string.

Example

The following now behaves consistently:

import polars as pl
records = [ {'a':1,'b':2}, {'a':2,'b':4} ]

pl.Series( values=records )
pl.DataFrame( records ).to_struct()

# shape: (2,)
# Series: '' [struct[2]]
# [
#   {1,2}
#   {2,4}
# ]

Previously the second of these would result in the following error:

TypeError: 
  DataFrame.to_struct() missing 1 required positional argument: 'name'

…e usual default Series name (empty string)
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Dec 11, 2023
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

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

Yep seems reasonable, thanks!

@alexander-beedie alexander-beedie merged commit cb854dd into pola-rs:main Dec 11, 2023
20 checks passed
@alexander-beedie alexander-beedie deleted the default-struct-series-name branch December 11, 2023 21:57
@stinodego stinodego changed the title feat(python): default to_struct Series name made consistent with the usual default Series name (empty string) feat(python): Add default to_struct Series name consistent with the usual default Series name (empty string) Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.to_struct should have optional name
2 participants