Skip to content

Commit

Permalink
schema -> names in dataframe_from_2d_array (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Nov 20, 2023
1 parent d896e65 commit caf0689
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
28 changes: 19 additions & 9 deletions spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ def column_from_1d_array(array: Any, *, name: str = "") -> Column:
See `dataframe_from_2d_array` for related 2D function.
Only Array-API-compliant 1D arrays are supported.
Cross-kind casting is undefined and may vary across implementations.
Downcasting is disallowed.
The resulting column will have the dtype to the
The resulting column will have the dtype corresponding to the
Array API one:
- 'bool' -> Bool()
Expand Down Expand Up @@ -170,22 +168,34 @@ def column_from_1d_array(array: Any, *, name: str = "") -> Column:
...


def dataframe_from_2d_array(array: Any, *, schema: dict[str, DType]) -> DataFrame:
def dataframe_from_2d_array(array: Any, *, names: Sequence[str]) -> DataFrame:
"""Construct DataFrame from 2D array.
See `column_from_1d_array` for related 1D function.
Only Array-API-compliant 2D arrays are supported.
Cross-kind casting is undefined and may vary across implementations.
Downcasting is disallowed.
The resulting columns will have the dtype corresponding to the
Array API one:
- 'bool' -> Bool()
- 'int8' -> Int8()
- 'int16' -> Int16()
- 'int32' -> Int32()
- 'int64' -> Int64()
- 'uint8' -> UInt8()
- 'uint16' -> UInt16()
- 'uint32' -> UInt32()
- 'uint64' -> UInt64()
- 'float32' -> Float32()
- 'float64' -> Float64()
Parameters
----------
array : array
array-API compliant 2D array
dtypes : Mapping[str, DType]
Dtype of each column. Must be the same length as ``array.shape[1]``.
Keys determine column names.
names : Sequence[str]
Names to give columns.
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion spec/API_specification/dataframe_api/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def dataframe_from_2d_array(
self,
array: Any,
*,
schema: dict[str, DType],
names: Sequence[str],
) -> DataFrame:
...

Expand Down
5 changes: 1 addition & 4 deletions spec/API_specification/examples/04_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI:
)
arr = df.to_array(namespace.Int64())
arr = some_array_function(arr)
df = namespace.dataframe_from_2d_array(
arr,
schema={"a": df.col("a").dtype, "b": namespace.Float64()},
)
df = namespace.dataframe_from_2d_array(arr, names=["a", "b"])
return df.dataframe

0 comments on commit caf0689

Please sign in to comment.