-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consistently raise
ColumnNotFoundError
for missing columns in…
… `select` and `drop` (#1389) --------- Co-authored-by: Marco Gorelli <[email protected]>
- Loading branch information
1 parent
0908f20
commit 0a5c8b9
Showing
8 changed files
with
160 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
|
||
class ColumnNotFoundError(Exception): ... | ||
class FormattedKeyError(KeyError): | ||
"""KeyError with formatted error message. | ||
Python's `KeyError` has special casing around formatting | ||
(see https://bugs.python.org/issue2651). Use this class when the error | ||
message has newlines and other special format characters. | ||
Needed by https://github.com/tensorflow/tensorflow/issues/36857. | ||
""" | ||
|
||
def __init__(self, message: str) -> None: | ||
self.message = message | ||
|
||
def __str__(self) -> str: | ||
return self.message | ||
|
||
|
||
class ColumnNotFoundError(FormattedKeyError): | ||
def __init__(self, message: str) -> None: | ||
self.message = message | ||
super().__init__(self.message) | ||
|
||
@classmethod | ||
def from_missing_and_available_column_names( | ||
cls, missing_columns: list[str], available_columns: list[str] | ||
) -> ColumnNotFoundError: | ||
message = ( | ||
f"The following columns were not found: {missing_columns}" | ||
f"\n\nHint: Did you mean one of these columns: {available_columns}?" | ||
) | ||
return ColumnNotFoundError(message) | ||
|
||
|
||
class InvalidOperationError(Exception): ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters