Skip to content

CLN: avoid bare except in libfrequencies #28344

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

Merged
merged 2 commits into from
Sep 9, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pandas/_libs/tslibs/frequencies.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ cpdef get_freq_code(freqstr):
if is_integer_object(freqstr[0]) and is_integer_object(freqstr[1]):
# e.g., freqstr = (2000, 1)
return freqstr
elif is_integer_object(freqstr[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you update the doc-string to add Raises (TypeError)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated and green

# Note: passing freqstr[1] below will raise TypeError if that
# is not a str
code = _period_str_to_code(freqstr[1])
stride = freqstr[0]
return code, stride
else:
# e.g., freqstr = ('T', 5)
try:
code = _period_str_to_code(freqstr[0])
stride = freqstr[1]
except:
if is_integer_object(freqstr[1]):
raise
code = _period_str_to_code(freqstr[1])
stride = freqstr[0]
code = _period_str_to_code(freqstr[0])
stride = freqstr[1]
return code, stride

if is_integer_object(freqstr):
Expand All @@ -177,7 +177,7 @@ cpdef get_freq_code(freqstr):
return code, stride


cpdef _base_and_stride(freqstr):
cpdef _base_and_stride(str freqstr):
"""
Return base freq and stride info from string representation

Expand Down Expand Up @@ -207,7 +207,7 @@ cpdef _base_and_stride(freqstr):
return base, stride


cpdef _period_str_to_code(freqstr):
cpdef _period_str_to_code(str freqstr):
freqstr = _lite_rule_alias.get(freqstr, freqstr)

if freqstr not in _dont_uppercase:
Expand Down