forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parameterize tests in scalar/timedelta (pandas-dev#20428)
- Loading branch information
Showing
2 changed files
with
29 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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 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,28 @@ | ||
# -*- 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 | ||
|
||
from pandas import Timedelta | ||
|
||
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 | ||
@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 | ||
|
||
td = Timedelta(nanoseconds=123) | ||
result = td.isoformat() | ||
expected = 'P0DT0H0M0.000000123S' | ||
assert result == expected | ||
|
||
@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 | ||
td = Timedelta(microseconds=10) | ||
result = td.isoformat() | ||
expected = 'P0DT0H0M0.00001S' | ||
assert result == expected | ||
|
||
(Timedelta(microseconds=10), 'P0DT0H0M0.00001S'), | ||
# trim micro | ||
td = Timedelta(milliseconds=1) | ||
result = td.isoformat() | ||
expected = 'P0DT0H0M0.001S' | ||
assert result == expected | ||
|
||
(Timedelta(milliseconds=1), 'P0DT0H0M0.001S'), | ||
# don't strip every 0 | ||
result = Timedelta(minutes=1).isoformat() | ||
expected = 'P0DT0H1M0S' | ||
assert result == expected | ||
(Timedelta(minutes=1), 'P0DT0H1M0S')]) | ||
def test_isoformat(td, expected_iso): | ||
assert td.isoformat() == expected_iso |