Skip to content

Commit c6012e3

Browse files
aoright辰言cclauss
authored
feat(conversions): add input validation and lowercase support to excel_title_to_column (#14872)
* feat(conversions): add input validation and lowercase support to excel_title_to_column * style(conversions): shorten ValueError message to comply with ruff E501 line length limit * Apply suggestion from @cclauss --------- Co-authored-by: 辰言 <oncwnuIWp30GguOyJ615Fqj8H-yc@git.weixin.qq.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 24719d0 commit c6012e3

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

conversions/excel_title_to_column.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ def excel_title_to_column(column_title: str) -> int:
1212
28
1313
>>> excel_title_to_column("Z")
1414
26
15+
>>> excel_title_to_column("a")
16+
1
17+
>>> excel_title_to_column("ab")
18+
28
19+
>>> excel_title_to_column("")
20+
Traceback (most recent call last):
21+
...
22+
ValueError: Column title must contain only alphabetic characters.
23+
>>> excel_title_to_column("A1")
24+
Traceback (most recent call last):
25+
...
26+
ValueError: Column title must contain only alphabetic characters.
1527
"""
16-
assert column_title.isupper()
28+
if not column_title or not column_title.isalpha():
29+
msg = "Column title must contain only alphabetic characters."
30+
raise ValueError(msg)
31+
32+
column_title = column_title.upper()
1733
answer = 0
1834
index = len(column_title) - 1
1935
power = 0

0 commit comments

Comments
 (0)