Skip to content

Commit d6ac338

Browse files
authored
Add 2d constructor (#208)
* add 2d constructor * add names and dtypes params * add column from 1d array too * add note about casting
1 parent e60739c commit d6ac338

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

spec/API_specification/dataframe_api/__init__.py

+53
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"DataFrame",
1616
"Column",
1717
"column_from_sequence",
18+
"column_from_1d_array",
1819
"concat",
1920
"dataframe_from_dict",
21+
"dataframe_from_2d_array",
2022
"is_null",
2123
"null",
2224
"Int64",
@@ -105,6 +107,57 @@ def dataframe_from_dict(data: Mapping[str, Column[Any]]) -> DataFrame:
105107
"""
106108
...
107109

110+
111+
def column_from_1d_array(array: Any, *, name: str, dtype: Any) -> Column[Any]:
112+
"""
113+
Construct Column from 1D array.
114+
115+
See `dataframe_from_2d_array` for related 2D function.
116+
117+
Only Array-API-compliant 1D arrays are supported.
118+
Cross-kind casting is undefined and may vary across implementations.
119+
Downcasting is disallowed.
120+
121+
Parameters
122+
----------
123+
array : array
124+
array-API compliant 1D array
125+
name : str
126+
Name to give columns.
127+
dtype : DType
128+
Dtype of column.
129+
130+
Returns
131+
-------
132+
Column
133+
"""
134+
...
135+
136+
def dataframe_from_2d_array(array: Any, *, names: Sequence[str], dtypes: Mapping[str, Any]) -> DataFrame:
137+
"""
138+
Construct DataFrame from 2D array.
139+
140+
See `column_from_1d_array` for related 1D function.
141+
142+
Only Array-API-compliant 2D arrays are supported.
143+
Cross-kind casting is undefined and may vary across implementations.
144+
Downcasting is disallowed.
145+
146+
Parameters
147+
----------
148+
array : array
149+
array-API compliant 2D array
150+
names : Sequence[str]
151+
Names to give columns. Must be the same length as ``array.shape[1]``.
152+
dtypes : Mapping[str, DType]
153+
Dtype of each column. Must be the same length as ``array.shape[1]``.
154+
155+
Returns
156+
-------
157+
DataFrame
158+
"""
159+
...
160+
108161
class null:
109162
"""
110163
A `null` object to represent missing data.

spec/API_specification/index.rst

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ of objects and functions in the top-level namespace. The latter are:
2727
Float64
2828
Float32
2929
Bool
30+
column_from_sequence
31+
column_from_1d_array
32+
dataframe_from_dict
33+
dataframe_from_2d_array
3034

3135
The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following
3236
methods and attributes:

0 commit comments

Comments
 (0)