Skip to content

Commit b3a52f5

Browse files
committed
Merge pull request #6391 from ischwabacher/patch-1
BUG: Fix behavior of to_offset with leading zeroes
2 parents fd5bfe0 + b9fb128 commit b3a52f5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Improvements to existing features
107107
Bug Fixes
108108
~~~~~~~~~
109109

110+
- Bug in ``pd.tseries.frequencies.to_offset`` when argument has leading zeroes (:issue:`6391`)
110111
- Bug in version string gen. for dev versions with shallow clones / install from tarball (:issue:`6127`)
111112
- Inconsistent tz parsing Timestamp/to_datetime for current year (:issue:`5958`)
112113
- Indexing bugs with reordered indexes (:issue:`6252`, :issue:`6254`)

pandas/tseries/frequencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ def to_offset(freqstr):
283283
try:
284284
for stride, name, _ in opattern.findall(freqstr):
285285
offset = get_offset(name)
286+
if stride_sign is None:
287+
stride_sign = -1 if stride.startswith('-') else 1
286288
if not stride:
287289
stride = 1
288290
stride = int(stride)
289-
if stride_sign is None:
290-
stride_sign = np.sign(stride)
291291
offset = offset * int(np.fabs(stride) * stride_sign)
292292
if delta is None:
293293
delta = offset

pandas/tseries/tests/test_frequencies.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def test_to_offset_negative():
7272
freqstr = '-5min10s'
7373
result = to_offset(freqstr)
7474
assert(result.n == -310)
75+
76+
77+
def test_to_offset_leading_zero():
78+
freqstr = '00H 00T 01S'
79+
result = to_offset(freqstr)
80+
assert(result.n == 1)
81+
82+
freqstr = '-00H 03T 14S'
83+
result = to_offset(freqstr)
84+
assert(result.n == -194)
7585

7686

7787
def test_anchored_shortcuts():

0 commit comments

Comments
 (0)