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

feat(api): add missing_ok: bool param to Table.drop() #10816

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NickCrews
Copy link
Contributor

resolves #10709

@github-actions github-actions bot added the tests Issues or PRs related to tests label Feb 10, 2025
This is useful if you need a column to not exist,
but you don't know if it does or not.

>>> t.drop("column_that_must_not_exist_afterwards") # doctest: +SKIP
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left out the specific error because I am worried that is going to change and become stale.
I would only want to show the actual error type if we remove the doctest: +SKIP marker, but I thought the extra boilerplate to actually be able to catch the error was not worth it. Open to adjusting this though.

if missing_ok:
return []
raise
except AttributeError as e:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needing to catch these two different kinds of exceptions here, and them being not very specific, I think really demonstrates the need for #10412

@@ -2401,6 +2403,28 @@ def drop(self, *fields: str | Selector) -> Table:
│ Torgersen │ 19.3 │ 193 │ 3450 │ female │ … │
└───────────┴───────────────┴───────────────────┴─────────────┴────────┴───┘

If a given column does not exist, then by default an error is raised.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If a given column does not exist, then by default an error is raised.
If a column does not exist, then by default an error is raised.

Comment on lines +2408 to +2409
This is useful if you need a column to not exist,
but you don't know if it does or not.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is useful if you need a column to not exist,
but you don't know if it does or not.

I don't this this bit of explanation is necessary.


>>> t.drop("column_that_must_not_exist_afterwards") # doctest: +SKIP
Traceback (most recent call last):
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...
...

return []
raise
except AttributeError as e:
if "has no attribute" in str(e):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for substrings in error messages is extremely fragile. The implementation of this functionality should basically never depend on the specific content an informational error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, binding for every column is very expensive for very wide tables.

Instead, what we should do is the following:

  1. Introduce FieldNotFoundError as you say
  2. Allow bind (perhaps through an option to _fast_bind?) to return an optimistic (possibly) subset: basically whatever columns are found from fields.

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

Successfully merging this pull request may close these issues.

feat: add missing_ok: bool = False kwarg to Table.drop() signature
2 participants