|
13 | 13 |
|
14 | 14 | from pandas import (Index, Series, TimeSeries, DataFrame,
|
15 | 15 | isnull, date_range, Timestamp, Period, DatetimeIndex,
|
16 |
| - Int64Index, to_datetime, bdate_range) |
| 16 | + Int64Index, to_datetime, bdate_range, Float64Index) |
17 | 17 |
|
18 | 18 | from pandas.core.daterange import DateRange
|
19 | 19 | import pandas.core.datetools as datetools
|
@@ -3287,6 +3287,91 @@ def test_guess_datetime_format_for_array(self):
|
3287 | 3287 | )
|
3288 | 3288 | self.assertTrue(format_for_string_of_nans is None)
|
3289 | 3289 |
|
| 3290 | + |
| 3291 | +class TestTimestampToJulianDate(tm.TestCase): |
| 3292 | + |
| 3293 | + def test_compare_1700(self): |
| 3294 | + r = Timestamp('1700-06-23').to_julian_date() |
| 3295 | + self.assertEqual(r, 2342145.5) |
| 3296 | + |
| 3297 | + def test_compare_2000(self): |
| 3298 | + r = Timestamp('2000-04-12').to_julian_date() |
| 3299 | + self.assertEqual(r, 2451646.5) |
| 3300 | + |
| 3301 | + def test_compare_2100(self): |
| 3302 | + r = Timestamp('2100-08-12').to_julian_date() |
| 3303 | + self.assertEqual(r, 2488292.5) |
| 3304 | + |
| 3305 | + def test_compare_hour01(self): |
| 3306 | + r = Timestamp('2000-08-12T01:00:00').to_julian_date() |
| 3307 | + self.assertEqual(r, 2451768.5416666666666666) |
| 3308 | + |
| 3309 | + def test_compare_hour13(self): |
| 3310 | + r = Timestamp('2000-08-12T13:00:00').to_julian_date() |
| 3311 | + self.assertEqual(r, 2451769.0416666666666666) |
| 3312 | + |
| 3313 | + |
| 3314 | +class TestDateTimeIndexToJulianDate(tm.TestCase): |
| 3315 | + def test_1700(self): |
| 3316 | + r1 = Float64Index([2345897.5, |
| 3317 | + 2345898.5, |
| 3318 | + 2345899.5, |
| 3319 | + 2345900.5, |
| 3320 | + 2345901.5]) |
| 3321 | + r2 = date_range(start=Timestamp('1710-10-01'), |
| 3322 | + periods=5, |
| 3323 | + freq='D').to_julian_date() |
| 3324 | + self.assert_(isinstance(r2, Float64Index)) |
| 3325 | + tm.assert_index_equal(r1, r2) |
| 3326 | + |
| 3327 | + def test_2000(self): |
| 3328 | + r1 = Float64Index([2451601.5, |
| 3329 | + 2451602.5, |
| 3330 | + 2451603.5, |
| 3331 | + 2451604.5, |
| 3332 | + 2451605.5]) |
| 3333 | + r2 = date_range(start=Timestamp('2000-02-27'), |
| 3334 | + periods=5, |
| 3335 | + freq='D').to_julian_date() |
| 3336 | + self.assert_(isinstance(r2, Float64Index)) |
| 3337 | + tm.assert_index_equal(r1, r2) |
| 3338 | + |
| 3339 | + def test_hour(self): |
| 3340 | + r1 = Float64Index([2451601.5, |
| 3341 | + 2451601.5416666666666666, |
| 3342 | + 2451601.5833333333333333, |
| 3343 | + 2451601.625, |
| 3344 | + 2451601.6666666666666666]) |
| 3345 | + r2 = date_range(start=Timestamp('2000-02-27'), |
| 3346 | + periods=5, |
| 3347 | + freq='H').to_julian_date() |
| 3348 | + self.assert_(isinstance(r2, Float64Index)) |
| 3349 | + tm.assert_index_equal(r1, r2) |
| 3350 | + |
| 3351 | + def test_minute(self): |
| 3352 | + r1 = Float64Index([2451601.5, |
| 3353 | + 2451601.5006944444444444, |
| 3354 | + 2451601.5013888888888888, |
| 3355 | + 2451601.5020833333333333, |
| 3356 | + 2451601.5027777777777777]) |
| 3357 | + r2 = date_range(start=Timestamp('2000-02-27'), |
| 3358 | + periods=5, |
| 3359 | + freq='T').to_julian_date() |
| 3360 | + self.assert_(isinstance(r2, Float64Index)) |
| 3361 | + tm.assert_index_equal(r1, r2) |
| 3362 | + |
| 3363 | + def test_second(self): |
| 3364 | + r1 = Float64Index([2451601.5, |
| 3365 | + 2451601.500011574074074, |
| 3366 | + 2451601.5000231481481481, |
| 3367 | + 2451601.5000347222222222, |
| 3368 | + 2451601.5000462962962962]) |
| 3369 | + r2 = date_range(start=Timestamp('2000-02-27'), |
| 3370 | + periods=5, |
| 3371 | + freq='S').to_julian_date() |
| 3372 | + self.assert_(isinstance(r2, Float64Index)) |
| 3373 | + tm.assert_index_equal(r1, r2) |
| 3374 | + |
3290 | 3375 | if __name__ == '__main__':
|
3291 | 3376 | nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
|
3292 | 3377 | exit=False)
|
0 commit comments