Skip to content

remove names from dataframe_from_2d_array #302

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 4 commits into from
Oct 27, 2023

Conversation

MarcoGorelli
Copy link
Contributor

The keys of dtypes already give the column names, and Python dicts are ordered

If anyone needs to reorder the names after construction, they can put .select after this method anyway

But having to always provide both dtypes and names is quite annoying from a user perspective

@@ -135,7 +135,7 @@ def column_from_1d_array(array: Any, *, dtype: DType, name: str = '') -> Column:
"""
...

def dataframe_from_2d_array(array: Any, *, names: Sequence[str], dtypes: Mapping[str, Any]) -> DataFrame:
def dataframe_from_2d_array(array: Any, *, dtypes: Mapping[str, Any]) -> DataFrame:
Copy link
Collaborator

@kkraus14 kkraus14 Oct 27, 2023

Choose a reason for hiding this comment

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

Does Mapping guarantee ordering? As far as I can tell it only guarantees that __getitem__, __len__, and __iter__ are supported, but doesn't guarantee any specific order for __iter__?

Not sure if this is actually an issue in practice though. Worst case we could dictate Dict instead of Mapping here?

@@ -137,7 +137,7 @@ def column_from_1d_array(array: Any, *, dtype: DType, name: str = '') -> Column:
"""
...

def dataframe_from_2d_array(array: Any, *, names: Sequence[str], dtypes: Mapping[str, Any]) -> DataFrame:
def dataframe_from_2d_array(array: Any, *, dtypes: Dict[str, Any]) -> DataFrame:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: but we have a schema function that is logically equivalent to what we expect here. Maybe rename this parameter to schema to be consistent?

Seeing dtypes makes me think I can pass a sequence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right thanks for spotting this

@kkraus14 kkraus14 merged commit c4ab5b4 into data-apis:main Oct 27, 2023
MarcoGorelli added a commit to MarcoGorelli/dataframe-api that referenced this pull request Oct 31, 2023
* remove `names` from dataframe_from_2d_array

* Mapping -> Dict

* rename to schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants