Skip to content

Replace dataframe_from_dict with dataframe_from_columns #276

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 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"column_from_sequence",
"column_from_1d_array",
"concat",
"dataframe_from_dict",
"dataframe_from_columns",
"dataframe_from_2d_array",
"is_null",
"null",
Expand Down Expand Up @@ -91,27 +91,20 @@ def column_from_sequence(sequence: Sequence[Any], *, dtype: DType, name: str = '
"""
...

def dataframe_from_dict(data: Mapping[str, Column]) -> DataFrame:
def dataframe_from_columns(*columns: Column) -> DataFrame:
"""
Construct DataFrame from map of column names to Columns.
Construct DataFrame from sequence of Columns.

Parameters
----------
data : Mapping[str, Column]
Column must be of the corresponding type of the DataFrame.
columns : Column
Column(s) must be of the corresponding type of the DataFrame.
For example, it is only supported to build a ``LibraryXDataFrame`` using
``LibraryXColumn`` instances.

Returns
-------
DataFrame

Raises
------
ValueError
If any of the columns already has a name, and the corresponding key
in `data` doesn't match.

"""
...

Expand Down
4 changes: 1 addition & 3 deletions spec/API_specification/dataframe_api/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ def column_from_sequence(
...

@staticmethod
def dataframe_from_dict(
data: Mapping[str, Column]
) -> DataFrame:
def dataframe_from_columns(*columns: Column) -> DataFrame:
...

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion spec/API_specification/examples/02_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def group_by_and_plot(

namespace = x.__column_namespace__()

df = namespace.dataframe_from_dict({"x": x, "y": y, "color": color})
df = namespace.dataframe_from_columns(
x.rename('x'), y.rename('y'), color.rename('color')
)

agg = df.group_by("color").mean()
x = agg.get_column_by_name("x").to_array_object(namespace.Float64())
Expand Down
2 changes: 1 addition & 1 deletion spec/API_specification/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ of objects and functions in the top-level namespace. The latter are:
is_dtype
column_from_sequence
column_from_1d_array
dataframe_from_dict
dataframe_from_columns
dataframe_from_2d_array

The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following
Expand Down