|
25 | 25 | # Usually we wouldn't want this import in this test file (which is targeted at
|
26 | 26 | # tslibs.parsing), but it is convenient to test the Timestamp constructor at
|
27 | 27 | # the same time as the other parsing functions.
|
28 |
| -from pandas import Timestamp |
| 28 | +from pandas import ( |
| 29 | + Timestamp, |
| 30 | + option_context, |
| 31 | +) |
29 | 32 | import pandas._testing as tm
|
30 | 33 | from pandas._testing._hypothesis import DATETIME_NO_TZ
|
31 | 34 |
|
@@ -422,3 +425,40 @@ def test_hypothesis_delimited_date(
|
422 | 425 |
|
423 | 426 | assert except_out_dateutil == except_in_dateutil
|
424 | 427 | assert result == expected
|
| 428 | + |
| 429 | + |
| 430 | +@pytest.mark.parametrize("input", ["21-01-01", "01-01-21"]) |
| 431 | +@pytest.mark.parametrize("dayfirst", [True, False]) |
| 432 | +def test_parse_datetime_string_with_reso_dayfirst(dayfirst, input): |
| 433 | + with option_context("display.date_dayfirst", dayfirst): |
| 434 | + except_out_dateutil, result = _helper_hypothesis_delimited_date( |
| 435 | + parsing.parse_datetime_string_with_reso, input |
| 436 | + ) |
| 437 | + |
| 438 | + except_in_dateutil, expected = _helper_hypothesis_delimited_date( |
| 439 | + du_parse, |
| 440 | + input, |
| 441 | + default=datetime(1, 1, 1), |
| 442 | + dayfirst=dayfirst, |
| 443 | + yearfirst=False, |
| 444 | + ) |
| 445 | + assert except_out_dateutil == except_in_dateutil |
| 446 | + assert result[0] == expected |
| 447 | + |
| 448 | + |
| 449 | +@pytest.mark.parametrize("input", ["21-01-01", "01-01-21"]) |
| 450 | +@pytest.mark.parametrize("yearfirst", [True, False]) |
| 451 | +def test_parse_datetime_string_with_reso_yearfirst(yearfirst, input): |
| 452 | + with option_context("display.date_yearfirst", yearfirst): |
| 453 | + except_out_dateutil, result = _helper_hypothesis_delimited_date( |
| 454 | + parsing.parse_datetime_string_with_reso, input |
| 455 | + ) |
| 456 | + except_in_dateutil, expected = _helper_hypothesis_delimited_date( |
| 457 | + du_parse, |
| 458 | + input, |
| 459 | + default=datetime(1, 1, 1), |
| 460 | + dayfirst=False, |
| 461 | + yearfirst=yearfirst, |
| 462 | + ) |
| 463 | + assert except_out_dateutil == except_in_dateutil |
| 464 | + assert result[0] == expected |
0 commit comments