-
Notifications
You must be signed in to change notification settings - Fork 156
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
Allow assigning lists and tuples to columns #3438
Comments
I don't see we ever claimed it is possible to assign a list of python primitives to a frame column: https://datatable.readthedocs.io/en/latest/api/frame/__setitem__.html But if you do DT1['B'] = dt.Frame([4, 5, 6]) this will actually work. |
Well, that's true, but it would be welcome and very handy, especially given the stated goal of "Interoperability with pandas / numpy / pyarrow / pure python: the users should have the ability to convert to another data-processing framework with ease." Lists and tuples are of course foundational in Python and I haven't used pyarrow, but pandas and numpy can both load columns/arrays, etc directly from lists or tuples. Should I close this issue and perhaps create a feature request instead? Thank you for your response, Kevin |
@kevinanewman Yes, I don’t really know why this is not supported yet, may be there was a reason. Could also be it was just missed, because we do support assigning scalars or numpy arrays/ranges (that looks undocumented). No need to close this issue, just rename it and update the text, so that it is clear this is FR and not a bug. |
Ok, I updated the title and revised the original post to make it consistent with a feature request. Thank you! |
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
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()
In case it is not obvious, please tell us what result should your code
produce.
as above
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)
The text was updated successfully, but these errors were encountered: