@@ -621,10 +621,51 @@ def test_basics_nanos(self):
621
621
assert stamp .microsecond == 145224
622
622
assert stamp .nanosecond == 192
623
623
624
- def test_unit (self ):
625
-
626
- def check (val , unit = None , h = 1 , s = 1 , us = 0 ):
627
- stamp = Timestamp (val , unit = unit )
624
+ @pytest .mark .parametrize ('value, check_kwargs' , [
625
+ [946688461000000000 , {}],
626
+ [946688461000000000 / long (1000 ), dict (unit = 'us' )],
627
+ [946688461000000000 / long (1000000 ), dict (unit = 'ms' )],
628
+ [946688461000000000 / long (1000000000 ), dict (unit = 's' )],
629
+ [10957 , dict (unit = 'D' , h = 0 )],
630
+ pytest .param ((946688461000000000 + 500000 ) / long (1000000000 ),
631
+ dict (unit = 's' , us = 499 , ns = 964 ),
632
+ marks = pytest .mark .skipif (not PY3 ,
633
+ reason = 'using truediv, so these'
634
+ ' are like floats' )),
635
+ pytest .param ((946688461000000000 + 500000000 ) / long (1000000000 ),
636
+ dict (unit = 's' , us = 500000 ),
637
+ marks = pytest .mark .skipif (not PY3 ,
638
+ reason = 'using truediv, so these'
639
+ ' are like floats' )),
640
+ pytest .param ((946688461000000000 + 500000 ) / long (1000000 ),
641
+ dict (unit = 'ms' , us = 500 ),
642
+ marks = pytest .mark .skipif (not PY3 ,
643
+ reason = 'using truediv, so these'
644
+ ' are like floats' )),
645
+ pytest .param ((946688461000000000 + 500000 ) / long (1000000000 ),
646
+ dict (unit = 's' ),
647
+ marks = pytest .mark .skipif (PY3 ,
648
+ reason = 'get chopped in py2' )),
649
+ pytest .param ((946688461000000000 + 500000000 ) / long (1000000000 ),
650
+ dict (unit = 's' ),
651
+ marks = pytest .mark .skipif (PY3 ,
652
+ reason = 'get chopped in py2' )),
653
+ pytest .param ((946688461000000000 + 500000 ) / long (1000000 ),
654
+ dict (unit = 'ms' ),
655
+ marks = pytest .mark .skipif (PY3 ,
656
+ reason = 'get chopped in py2' )),
657
+ [(946688461000000000 + 500000 ) / long (1000 ), dict (unit = 'us' , us = 500 )],
658
+ [(946688461000000000 + 500000000 ) / long (1000000 ),
659
+ dict (unit = 'ms' , us = 500000 )],
660
+ [946688461000000000 / 1000.0 + 5 , dict (unit = 'us' , us = 5 )],
661
+ [946688461000000000 / 1000.0 + 5000 , dict (unit = 'us' , us = 5000 )],
662
+ [946688461000000000 / 1000000.0 + 0.5 , dict (unit = 'ms' , us = 500 )],
663
+ [946688461000000000 / 1000000.0 + 0.005 , dict (unit = 'ms' , us = 5 , ns = 5 )],
664
+ [946688461000000000 / 1000000000.0 + 0.5 , dict (unit = 's' , us = 500000 )],
665
+ [10957 + 0.5 , dict (unit = 'D' , h = 12 )]])
666
+ def test_unit (self , value , check_kwargs ):
667
+ def check (value , unit = None , h = 1 , s = 1 , us = 0 , ns = 0 ):
668
+ stamp = Timestamp (value , unit = unit )
628
669
assert stamp .year == 2000
629
670
assert stamp .month == 1
630
671
assert stamp .day == 1
@@ -637,41 +678,9 @@ def check(val, unit=None, h=1, s=1, us=0):
637
678
assert stamp .minute == 0
638
679
assert stamp .second == 0
639
680
assert stamp .microsecond == 0
640
- assert stamp .nanosecond == 0
641
-
642
- ts = Timestamp ('20000101 01:01:01' )
643
- val = ts .value
644
- days = (ts - Timestamp ('1970-01-01' )).days
645
-
646
- check (val )
647
- check (val / long (1000 ), unit = 'us' )
648
- check (val / long (1000000 ), unit = 'ms' )
649
- check (val / long (1000000000 ), unit = 's' )
650
- check (days , unit = 'D' , h = 0 )
681
+ assert stamp .nanosecond == ns
651
682
652
- # using truediv, so these are like floats
653
- if PY3 :
654
- check ((val + 500000 ) / long (1000000000 ), unit = 's' , us = 500 )
655
- check ((val + 500000000 ) / long (1000000000 ), unit = 's' , us = 500000 )
656
- check ((val + 500000 ) / long (1000000 ), unit = 'ms' , us = 500 )
657
-
658
- # get chopped in py2
659
- else :
660
- check ((val + 500000 ) / long (1000000000 ), unit = 's' )
661
- check ((val + 500000000 ) / long (1000000000 ), unit = 's' )
662
- check ((val + 500000 ) / long (1000000 ), unit = 'ms' )
663
-
664
- # ok
665
- check ((val + 500000 ) / long (1000 ), unit = 'us' , us = 500 )
666
- check ((val + 500000000 ) / long (1000000 ), unit = 'ms' , us = 500000 )
667
-
668
- # floats
669
- check (val / 1000.0 + 5 , unit = 'us' , us = 5 )
670
- check (val / 1000.0 + 5000 , unit = 'us' , us = 5000 )
671
- check (val / 1000000.0 + 0.5 , unit = 'ms' , us = 500 )
672
- check (val / 1000000.0 + 0.005 , unit = 'ms' , us = 5 )
673
- check (val / 1000000000.0 + 0.5 , unit = 's' , us = 500000 )
674
- check (days + 0.5 , unit = 'D' , h = 12 )
683
+ check (value , ** check_kwargs )
675
684
676
685
def test_roundtrip (self ):
677
686
0 commit comments