Skip to content
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

Table.remove() converts columns into lists #513

Closed
davidwagner opened this issue Sep 16, 2021 · 1 comment · Fixed by #526
Closed

Table.remove() converts columns into lists #513

davidwagner opened this issue Sep 16, 2021 · 1 comment · Fixed by #526

Comments

@davidwagner
Copy link
Member

When using Table.remove(), the type of the columns in a table become lists. They should remain arrays. See attached notebook for an example.

TableRemoveOddity.zip

Sample code to reproduce:

>>> newTable = Table().with_columns(
        "Teams", make_array('Aces', 'Bears', 'Cats', 'Dogs', 'Eagles', 'Ferrets'),
        "Scores", make_array(93, 87, 92, 75, 96, 68)
    )
>>> newTable.remove(0)
>>> newTable.column('Scores')
[87, 92, 75, 96, 68]
>>> type(newTable.column('Scores'))
list

Looking at the implementation of .remove() (https://github.com/data-8/datascience/blob/master/datascience/tables.py#L1118), we can immediately see the problem:

for col in self._columns:
            self._columns[col] = [elem for i, elem in enumerate(self[col]) if i not in rows_remove]

It creates a list, not an array. I believe this should be fixed to create an array.

(Seeing as .remove() is also side-effecting and we are trying to promote non-side-effecting methods where appropriate, we could consider deprecating .remove() anyway and pointing people to .exclude().)

Thanks to Dan Kaiser for this bug report.

@abhishict
Copy link
Contributor

I've fixed this issue in the above pull request, could you please review and approve. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants