Skip to content

Commit

Permalink
add issue number and try except
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Mar 19, 2018
1 parent 54c2491 commit 0e2a0cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def array_strptime(ndarray[object] values, object fmt,
break
elif parse_code == 19:
z = found_dict['z']
gmtoff, gmtoff_fraction = _parse_timezone_directive(z)
gmtoff, gmtoff_fraction = parse_timezone_directive(z)

# If we know the wk of the year and what day of that wk, we can figure
# out the Julian day of the year.
Expand Down Expand Up @@ -656,7 +656,7 @@ cdef _calc_julian_from_U_or_W(int year, int week_of_year,
days_to_week = week_0_length + (7 * (week_of_year - 1))
return 1 + days_to_week + day_of_week

cdef _parse_timezone_directive(object z):
cdef parse_timezone_directive(object z):
"""
Parse the '%z' directive and return an offset from UTC
Expand All @@ -674,22 +674,23 @@ cdef _parse_timezone_directive(object z):
object gmtoff_remainder, gmtoff_remainder_padding

if z == 'Z':
gmtoff = 0
gmtoff_fraction = 0
return (0, 0)
else:
if z[3] == ':':
z = z[:3] + z[4:]
if len(z) > 5:
if z[5] != ':':
msg = "Inconsistent use of : in {0}"
raise ValueError(msg.format(z))
z = z[:5] + z[6:]
hours = int(z[1:3])
minutes = int(z[3:5])
seconds = int(z[5:7] or 0)
gmtoff = (hours * 60 * 60) + (minutes * 60) + seconds
gmtoff_remainder = z[8:]

try:
if z[3] == ':':
z = z[:3] + z[4:]
if len(z) > 5:
if z[5] != ':':
msg = "Inconsistent use of : in {0}"
raise ValueError(msg.format(z))
z = z[:5] + z[6:]
hours = int(z[1:3])
minutes = int(z[3:5])
seconds = int(z[5:7] or 0)
gmtoff = (hours * 60 * 60) + (minutes * 60) + seconds
gmtoff_remainder = z[8:]
except ValueError:
raise ValueError("Could not parse offset: {0}".format(z))
# Pad to always return microseconds.
pad_number = 6 - len(gmtoff_remainder)
gmtoff_remainder_padding = "0" * pad_number
Expand All @@ -698,5 +699,4 @@ cdef _parse_timezone_directive(object z):
if z.startswith("-"):
gmtoff = -gmtoff
gmtoff_fraction = -gmtoff_fraction

return (gmtoff, gmtoff_fraction)
return (gmtoff, gmtoff_fraction)
2 changes: 2 additions & 0 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def test_to_datetime_format_weeks(self, cache):
def test_to_datetime_parse_tzname_or_tzoffset(self, box, const,
assert_equal, fmt,
dates, expected_dates):
# GH 13486
# %z or %Z parsing
result = pd.to_datetime(dates, format=fmt, box=box)
expected = const(expected_dates)
Expand All @@ -238,6 +239,7 @@ def test_to_datetime_parse_tzname_or_tzoffset(self, box, const,
def test_to_datetime_parse_tzname_and_tzoffset(self, box, const,
assert_equal, dates,
expected_dates):
# GH 13486
# %z and %Z parsing
fmt = '%Y-%m-%d %H:%M:%S %Z %z'
result = pd.to_datetime(dates, format=fmt, box=box)
Expand Down

0 comments on commit 0e2a0cd

Please sign in to comment.