-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Avoid Timedelta rounding when specifying unit and integer (#12690) #19732
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
Changes from all commits
d86f26b
3ffd35c
aa22c87
1c2360e
3f463ec
a4190a0
69ce6a6
04d97a2
0b83501
43ea477
44031c6
8c9f99f
8256870
ae1de9e
68d296d
9439463
358b595
461e0ee
d9d71e0
7ba45b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,22 +202,22 @@ cpdef inline int64_t cast_from_unit(object ts, object unit) except? -1: | |
|
||
if unit == 'D' or unit == 'd': | ||
m = 1000000000L * 86400 | ||
p = 6 | ||
p = 9 | ||
elif unit == 'h': | ||
m = 1000000000L * 3600 | ||
p = 6 | ||
p = 9 | ||
elif unit == 'm': | ||
m = 1000000000L * 60 | ||
p = 6 | ||
p = 9 | ||
elif unit == 's': | ||
m = 1000000000L | ||
p = 6 | ||
p = 9 | ||
elif unit == 'ms': | ||
m = 1000000L | ||
p = 3 | ||
p = 6 | ||
elif unit == 'us': | ||
m = 1000L | ||
p = 0 | ||
p = 3 | ||
elif unit == 'ns' or unit is None: | ||
m = 1L | ||
p = 0 | ||
|
@@ -231,10 +231,10 @@ cpdef inline int64_t cast_from_unit(object ts, object unit) except? -1: | |
# cast the unit, multiply base/frace separately | ||
# to avoid precision issues from float -> int | ||
base = <int64_t> ts | ||
frac = ts -base | ||
frac = ts - base | ||
if p: | ||
frac = round(frac, p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might be able to do something like this
|
||
return <int64_t> (base *m) + <int64_t> (frac *m) | ||
return <int64_t> (base * m) + <int64_t> (frac * m) | ||
|
||
|
||
cdef inline _decode_if_necessary(object ts): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,8 @@ def test_date_time(): | |
fname = os.path.join(dirpath, "datetime.csv") | ||
df0 = pd.read_csv(fname, parse_dates=['Date1', 'Date2', 'DateTime', | ||
'DateTimeHi', 'Taiw']) | ||
# GH 19732: Timestamps imported from sas will incur floating point errors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did this need to be changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe there are floating point errors when importing dates from the sas file.
I am not familiar with read_sas or the sas file that was created, but I am fairly certain it's due to the floating point errors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you round these instead of specifying exact values |
||
df.iloc[:, 3] = df.iloc[:, 3].dt.round('us') | ||
tm.assert_frame_equal(df, df0) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these were set originally to avoid precision issues.