-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
parameterize tests in scalar/timedelta #20428
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
89c57ff
parameterize test_formats.py
minggli f5f220b
parametrize test_td_constructor_on_nanoseconds in test_construction
minggli 29db679
separate td_constructor_value_error
minggli ea19226
more compact styling of parameters
minggli e5df1dd
more compact styling of parameters
minggli 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
from pandas import Timedelta | ||
|
||
|
||
def test_repr(): | ||
assert (repr(Timedelta(10, unit='d')) == | ||
"Timedelta('10 days 00:00:00')") | ||
assert (repr(Timedelta(10, unit='s')) == | ||
"Timedelta('0 days 00:00:10')") | ||
assert (repr(Timedelta(10, unit='ms')) == | ||
"Timedelta('0 days 00:00:00.010000')") | ||
assert (repr(Timedelta(-10, unit='ms')) == | ||
"Timedelta('-1 days +23:59:59.990000')") | ||
|
||
import pytest | ||
|
||
def test_isoformat(): | ||
td = Timedelta(days=6, minutes=50, seconds=3, | ||
milliseconds=10, microseconds=10, nanoseconds=12) | ||
expected = 'P6DT0H50M3.010010012S' | ||
result = td.isoformat() | ||
assert result == expected | ||
|
||
td = Timedelta(days=4, hours=12, minutes=30, seconds=5) | ||
result = td.isoformat() | ||
expected = 'P4DT12H30M5S' | ||
assert result == expected | ||
|
||
td = Timedelta(nanoseconds=123) | ||
result = td.isoformat() | ||
expected = 'P0DT0H0M0.000000123S' | ||
assert result == expected | ||
|
||
# trim nano | ||
td = Timedelta(microseconds=10) | ||
result = td.isoformat() | ||
expected = 'P0DT0H0M0.00001S' | ||
assert result == expected | ||
from pandas import Timedelta | ||
|
||
# trim micro | ||
td = Timedelta(milliseconds=1) | ||
result = td.isoformat() | ||
expected = 'P0DT0H0M0.001S' | ||
assert result == expected | ||
|
||
# don't strip every 0 | ||
result = Timedelta(minutes=1).isoformat() | ||
expected = 'P0DT0H1M0S' | ||
assert result == expected | ||
@pytest.mark.parametrize('td, expected_repr', | ||
[(Timedelta(10, unit='d'), | ||
"Timedelta('10 days 00:00:00')"), | ||
(Timedelta(10, unit='s'), | ||
"Timedelta('0 days 00:00:10')"), | ||
(Timedelta(10, unit='ms'), | ||
"Timedelta('0 days 00:00:00.010000')"), | ||
(Timedelta(-10, unit='ms'), | ||
"Timedelta('-1 days +23:59:59.990000')")]) | ||
def test_repr(td, expected_repr): | ||
assert repr(td) == expected_repr | ||
|
||
|
||
@pytest.mark.parametrize('td, expected_iso', | ||
[(Timedelta(days=6, minutes=50, seconds=3, | ||
milliseconds=10, microseconds=10, | ||
nanoseconds=12), | ||
'P6DT0H50M3.010010012S'), | ||
(Timedelta(days=4, hours=12, minutes=30, seconds=5), | ||
'P4DT12H30M5S'), | ||
(Timedelta(nanoseconds=123), | ||
'P0DT0H0M0.000000123S'), | ||
# trim nano | ||
(Timedelta(microseconds=10), | ||
'P0DT0H0M0.00001S'), | ||
# trim micro | ||
(Timedelta(milliseconds=1), | ||
'P0DT0H0M0.001S'), | ||
# don't strip every 0 | ||
(Timedelta(minutes=1), | ||
'P0DT0H1M0S')]) | ||
def test_isoformat(td, expected_iso): | ||
assert td.isoformat() == expected_iso |
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.
Just stylistically if you put the left bracket to start the list of parameters on the first line it could make this more readable (reduces the indentation required for every subsequent line)
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.
very good point. thanks!