-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Convert float freqstrs to ints at finer resolution #14378
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
jorisvandenbossche
merged 5 commits into
pandas-dev:master
from
jisantuc:frequencies-float-to-int
Dec 14, 2016
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
47723c3
Convert float freqstrs to ints at finer resolution
jisantuc 01afe8a
Bring back resolution definitions and move whatnew to 0.20
jisantuc fd95822
Merge remote-tracking branch 'upstream/master' into PR_TOOL_MERGE_PR_…
jorisvandenbossche 65a5163
reword whatsnew
jorisvandenbossche 80b6d5a
latest comments
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,21 @@ def test_to_offset_multiple(self): | |
expected = offsets.Hour(3) | ||
assert (result == expected) | ||
|
||
freqstr = '2h 20.5min' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Second(8430) | ||
assert (result == expected) | ||
|
||
freqstr = '1.5min' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Second(90) | ||
assert (result == expected) | ||
|
||
freqstr = '0.5S' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Milli(500) | ||
assert (result == expected) | ||
|
||
freqstr = '15l500u' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Micro(15500) | ||
|
@@ -49,6 +64,16 @@ def test_to_offset_multiple(self): | |
expected = offsets.Milli(10075) | ||
assert (result == expected) | ||
|
||
freqstr = '1s0.25ms' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Micro(1000250) | ||
assert (result == expected) | ||
|
||
freqstr = '1s0.25L' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Micro(1000250) | ||
assert (result == expected) | ||
|
||
freqstr = '2800N' | ||
result = frequencies.to_offset(freqstr) | ||
expected = offsets.Nano(2800) | ||
|
@@ -107,10 +132,8 @@ def test_to_offset_invalid(self): | |
frequencies.to_offset('-2-3U') | ||
with tm.assertRaisesRegexp(ValueError, 'Invalid frequency: -2D:3H'): | ||
frequencies.to_offset('-2D:3H') | ||
|
||
# ToDo: Must be fixed in #8419 | ||
with tm.assertRaisesRegexp(ValueError, 'Invalid frequency: .5S'): | ||
frequencies.to_offset('.5S') | ||
with tm.assertRaisesRegexp(ValueError, 'Invalid frequency: 1.5.0S'): | ||
frequencies.to_offset('1.5.0S') | ||
|
||
# split offsets with spaces are valid | ||
assert frequencies.to_offset('2D 3H') == offsets.Hour(51) | ||
|
@@ -379,6 +402,26 @@ def test_freq_to_reso(self): | |
result = Reso.get_freq(Reso.get_str(Reso.get_reso_from_freq(freq))) | ||
self.assertEqual(freq, result) | ||
|
||
def test_resolution_bumping(self): | ||
# GH 14378 | ||
Reso = frequencies.Resolution | ||
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 add the issue number here as as comment |
||
|
||
self.assertEqual(Reso.get_stride_from_decimal(1.5, 'T'), (90, 'S')) | ||
self.assertEqual(Reso.get_stride_from_decimal(62.4, 'T'), (3744, 'S')) | ||
self.assertEqual(Reso.get_stride_from_decimal(1.04, 'H'), (3744, 'S')) | ||
self.assertEqual(Reso.get_stride_from_decimal(1, 'D'), (1, 'D')) | ||
self.assertEqual(Reso.get_stride_from_decimal(0.342931, 'H'), | ||
(1234551600, 'U')) | ||
self.assertEqual(Reso.get_stride_from_decimal(1.2345, 'D'), | ||
(106660800, 'L')) | ||
|
||
with self.assertRaises(ValueError): | ||
Reso.get_stride_from_decimal(0.5, 'N') | ||
|
||
# too much precision in the input can prevent | ||
with self.assertRaises(ValueError): | ||
Reso.get_stride_from_decimal(0.3429324798798269273987982, 'H') | ||
|
||
def test_get_freq_code(self): | ||
# freqstr | ||
self.assertEqual(frequencies.get_freq_code('A'), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you add Parameters/Returns section to detail the args
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.
and Raises