-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Separate out non-scalar tests from scalar tests; move to ?? in follow-up #18142
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 11 commits
e7d5373
f99aa04
73e2f02
157c7fa
14810f6
cb932a2
c0a5f77
b575b3a
9f06079
f628aef
ea7d33b
817281b
e467040
66c65c1
f932060
16ccef4
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 |
---|---|---|
|
@@ -11,6 +11,17 @@ | |
class TestTimedeltaIndex(object): | ||
_multiprocess_can_split_ = True | ||
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. remove this |
||
|
||
def test_contains(self): | ||
# Checking for any NaT-like objects | ||
# GH 13603 | ||
td = pd.to_timedelta(range(5), unit='d') + pd.offsets.Hour(1) | ||
for v in [pd.NaT, None, float('nan'), np.nan]: | ||
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. maybe should consolidate these types of tests in scalar/test_nat.py (even though you are testing the index itself here). |
||
assert not (v in td) | ||
|
||
td = pd.to_timedelta([pd.NaT]) | ||
for v in [pd.NaT, None, float('nan'), np.nan]: | ||
assert (v in td) | ||
|
||
def test_insert(self): | ||
|
||
idx = TimedeltaIndex(['4day', '1day', '2day'], name='idx') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,57 @@ def test_numpy_minmax(self): | |
tm.assert_raises_regex( | ||
ValueError, errmsg, np.argmax, td, out=0) | ||
|
||
# TODO: Dedup with version below | ||
def test_round2(self): | ||
t1 = timedelta_range('1 days', periods=3, freq='1 min 2 s 3 us') | ||
t2 = -1 * t1 | ||
t1a = timedelta_range('1 days', periods=3, freq='1 min 2 s') | ||
t1c = pd.TimedeltaIndex([1, 1, 1], unit='D') | ||
|
||
# note that negative times round DOWN! so don't give whole numbers | ||
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. also should parametrize this (TODO) |
||
for (freq, s1, s2) in [('N', t1, t2), | ||
('U', t1, t2), | ||
('L', t1a, | ||
TimedeltaIndex(['-1 days +00:00:00', | ||
'-2 days +23:58:58', | ||
'-2 days +23:57:56'], | ||
dtype='timedelta64[ns]', | ||
freq=None) | ||
), | ||
('S', t1a, | ||
TimedeltaIndex(['-1 days +00:00:00', | ||
'-2 days +23:58:58', | ||
'-2 days +23:57:56'], | ||
dtype='timedelta64[ns]', | ||
freq=None) | ||
), | ||
('12T', t1c, | ||
TimedeltaIndex(['-1 days', | ||
'-1 days', | ||
'-1 days'], | ||
dtype='timedelta64[ns]', | ||
freq=None) | ||
), | ||
('H', t1c, | ||
TimedeltaIndex(['-1 days', | ||
'-1 days', | ||
'-1 days'], | ||
dtype='timedelta64[ns]', | ||
freq=None) | ||
), | ||
('d', t1c, | ||
pd.TimedeltaIndex([-1, -1, -1], unit='D') | ||
)]: | ||
|
||
r1 = t1.round(freq) | ||
tm.assert_index_equal(r1, s1) | ||
r2 = t2.round(freq) | ||
tm.assert_index_equal(r2, s2) | ||
|
||
# invalid | ||
for freq in ['Y', 'M', 'foobar']: | ||
pytest.raises(ValueError, lambda: t1.round(freq)) | ||
|
||
def test_round(self): | ||
td = pd.timedelta_range(start='16801 days', periods=5, freq='30Min') | ||
elt = td[1] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,3 +401,44 @@ def test_series_box_timedelta(self): | |
s = Series(rng) | ||
assert isinstance(s[1], Timedelta) | ||
assert isinstance(s.iat[2], Timedelta) | ||
|
||
|
||
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. make a note to parametrize this 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. Not clear what "this" is in context. 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. this is the calling of testit, simple enough should be to paramerize the units which its iterating |
||
class TestTimedeltaIndexVectorizedTimedelta(object): | ||
|
||
def test_nat_converters(self): | ||
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. we have a section on nat tests 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. There are many of these spread around. I really think we should focus for now on getting non-scalar tests out of scalar and recognize that this is a more-than-one-PR task. |
||
|
||
def testit(unit, transform): | ||
# array | ||
result = pd.to_timedelta(np.arange(5), unit=unit) | ||
expected = TimedeltaIndex([np.timedelta64(i, transform(unit)) | ||
for i in np.arange(5).tolist()]) | ||
tm.assert_index_equal(result, expected) | ||
|
||
# scalar | ||
result = pd.to_timedelta(2, unit=unit) | ||
expected = Timedelta(np.timedelta64(2, transform(unit)).astype( | ||
'timedelta64[ns]')) | ||
assert result == expected | ||
|
||
# validate all units | ||
# GH 6855 | ||
for unit in ['Y', 'M', 'W', 'D', 'y', 'w', 'd']: | ||
testit(unit, lambda x: x.upper()) | ||
for unit in ['days', 'day', 'Day', 'Days']: | ||
testit(unit, lambda x: 'D') | ||
for unit in ['h', 'm', 's', 'ms', 'us', 'ns', 'H', 'S', 'MS', 'US', | ||
'NS']: | ||
testit(unit, lambda x: x.lower()) | ||
|
||
# offsets | ||
|
||
# m | ||
testit('T', lambda x: 'm') | ||
|
||
# ms | ||
testit('L', lambda x: 'ms') | ||
|
||
def test_timedelta_hash_equality(self): | ||
# GH 11129 | ||
tds = timedelta_range('1 second', periods=20) | ||
assert all(hash(td) == hash(td.to_pytimedelta()) for td in tds) |
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.
this can be made a decorator FYI
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.
add a note to do this
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.
How does the decorator usage work? grepping didn't turn up any examples.