|
2 | 2 | """
|
3 | 3 | Tests for offsets.Tick and subclasses
|
4 | 4 | """
|
| 5 | +from __future__ import division |
| 6 | + |
5 | 7 | from datetime import datetime, timedelta
|
6 | 8 |
|
7 | 9 | from hypothesis import assume, example, given, settings, strategies as st
|
@@ -36,6 +38,10 @@ def test_delta_to_tick():
|
36 | 38 | tick = offsets._delta_to_tick(delta)
|
37 | 39 | assert (tick == offsets.Day(3))
|
38 | 40 |
|
| 41 | + td = Timedelta(nanoseconds=5) |
| 42 | + tick = offsets._delta_to_tick(td) |
| 43 | + assert tick == Nano(5) |
| 44 | + |
39 | 45 |
|
40 | 46 | @pytest.mark.parametrize('cls', tick_classes)
|
41 | 47 | @settings(deadline=None) # GH 24641
|
@@ -228,6 +234,34 @@ def test_tick_addition(kls, expected):
|
228 | 234 | assert result == expected
|
229 | 235 |
|
230 | 236 |
|
| 237 | +@pytest.mark.parametrize('cls', tick_classes) |
| 238 | +def test_tick_division(cls): |
| 239 | + off = cls(10) |
| 240 | + |
| 241 | + assert off / cls(5) == 2 |
| 242 | + assert off / 2 == cls(5) |
| 243 | + assert off / 2.0 == cls(5) |
| 244 | + |
| 245 | + assert off / off.delta == 1 |
| 246 | + assert off / off.delta.to_timedelta64() == 1 |
| 247 | + |
| 248 | + assert off / Nano(1) == off.delta / Nano(1).delta |
| 249 | + |
| 250 | + if cls is not Nano: |
| 251 | + # A case where we end up with a smaller class |
| 252 | + result = off / 1000 |
| 253 | + assert isinstance(result, offsets.Tick) |
| 254 | + assert not isinstance(result, cls) |
| 255 | + assert result.delta == off.delta / 1000 |
| 256 | + |
| 257 | + if cls._inc < Timedelta(seconds=1): |
| 258 | + # Case where we end up with a bigger class |
| 259 | + result = off / .001 |
| 260 | + assert isinstance(result, offsets.Tick) |
| 261 | + assert not isinstance(result, cls) |
| 262 | + assert result.delta == off.delta / .001 |
| 263 | + |
| 264 | + |
231 | 265 | @pytest.mark.parametrize('cls1', tick_classes)
|
232 | 266 | @pytest.mark.parametrize('cls2', tick_classes)
|
233 | 267 | def test_tick_zero(cls1, cls2):
|
|
0 commit comments