h2oai / h2oai/datatable

Allow assigning lists and tuples to columns

Open
#3,438 4 comments 0 reactions 0 assignees View on GitHub
new feature
Dominant language
C++
Stars
1.9k
Forks
164
Avg merge
7h 31m
Merged PRs (30d)
1

Description

### Add feature to be able to assign/update columns from lists or tuples of values if the list or tuple contains the correct number of elements

Pandas, numpy and datable (in Frame constructors) support column creation directly from lists or tuples, but in datatable once the Frame is created it's not possible to create new or update existing columns directly from lists.

### fail using list of values
```
import datatable as dt
import numpy as np

DT1 = dt.Frame({'A': [1, 2, 3]}). # create single-column Frame from list of values SUCCESS
DT1['A'] = [7, 8, 9] # update existing column from list of values FAIL
DT1['B'] = [4, 5, 6] # create new column from list of values FAIL
```

Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "", line 1, in
datatable.exceptions.ValueError: The LHS of the replacement has 1 columns, while the RHS has 3 replacement expressions

### fail using tuple of values
`DT1['B'] = (4, 5, 6) # FAIL`

Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "", line 1, in
datatable.exceptions.ValueError: The LHS of the replacement has 1 columns, while the RHS has 3 replacement expressions

### fail using update() and list of values
`DT1[:, update(B=[7, 8, 9])] # FAIL`

Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
File "", line 1, in
datatable.exceptions.ValueError: The LHS of the replacement has 1 columns, while the RHS has 3 replacement expressions

### success using np.array() and range()
```
DT1['B'] = np.array([4, 5, 6]) # SUCCESS
DT1['C'] = range(3) # SUCCESS
print(DT1)

DT1
| A B C
| int32 int64 int32
-- + ----- ----- -----
0 | 1 4 0
1 | 2 5 1
2 | 3 6 2
[3 rows x 3 columns]
```

- What was the expected behavior?
In case it is not obvious, please tell us what result should your code
produce.

as above

- Your environment?
What is your datatable version, python version, and operating system?

datatable version 1.0.0, python 3.8 (x86), macOS 13.2.1 (22D68)
and also
datatable version 1.1.0a0+build.1677978121.kevinnewman, python 3.9 (M1 ARM), macOS 13.2.1 (22D68)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.