test_ccalendar.py 717 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. import numpy as np
  4. import pytest
  5. from pandas._libs.tslibs import ccalendar
  6. @pytest.mark.parametrize("date_tuple,expected", [
  7. ((2001, 3, 1), 60),
  8. ((2004, 3, 1), 61),
  9. ((1907, 12, 31), 365), # End-of-year, non-leap year.
  10. ((2004, 12, 31), 366), # End-of-year, leap year.
  11. ])
  12. def test_get_day_of_year_numeric(date_tuple, expected):
  13. assert ccalendar.get_day_of_year(*date_tuple) == expected
  14. def test_get_day_of_year_dt():
  15. dt = datetime.fromordinal(1 + np.random.randint(365 * 4000))
  16. result = ccalendar.get_day_of_year(dt.year, dt.month, dt.day)
  17. expected = (dt - dt.replace(month=1, day=1)).days + 1
  18. assert result == expected