|
10 | 10 | import numpy as np |
11 | 11 | import pytest |
12 | 12 |
|
13 | | -from pandas._config import set_option |
| 13 | +from pandas import option_context |
14 | 14 |
|
15 | 15 | from pandas._libs.tslibs import ( |
16 | 16 | parsing, |
@@ -428,34 +428,35 @@ def test_hypothesis_delimited_date( |
428 | 428 | @pytest.mark.parametrize("input", ["21-01-01", "01-01-21"]) |
429 | 429 | @pytest.mark.parametrize("dayfirst", [True, False]) |
430 | 430 | def test_parse_datetime_string_with_reso_dayfirst(dayfirst, input): |
431 | | - set_option("display.date_dayfirst", dayfirst) |
432 | | - except_out_dateutil, result = _helper_hypothesis_delimited_date( |
433 | | - parsing.parse_datetime_string_with_reso, input |
434 | | - ) |
435 | | - except_in_dateutil, expected = _helper_hypothesis_delimited_date( |
436 | | - du_parse, |
437 | | - input, |
438 | | - default=datetime(1, 1, 1), |
439 | | - dayfirst=dayfirst, |
440 | | - yearfirst=False, |
441 | | - ) |
442 | | - assert except_out_dateutil == except_in_dateutil |
443 | | - assert result[0] == expected |
| 431 | + with option_context("display.date_dayfirst", dayfirst): |
| 432 | + except_out_dateutil, result = _helper_hypothesis_delimited_date( |
| 433 | + parsing.parse_datetime_string_with_reso, input |
| 434 | + ) |
| 435 | + |
| 436 | + except_in_dateutil, expected = _helper_hypothesis_delimited_date( |
| 437 | + du_parse, |
| 438 | + input, |
| 439 | + default=datetime(1, 1, 1), |
| 440 | + dayfirst=dayfirst, |
| 441 | + yearfirst=False, |
| 442 | + ) |
| 443 | + assert except_out_dateutil == except_in_dateutil |
| 444 | + assert result[0] == expected |
444 | 445 |
|
445 | 446 |
|
446 | 447 | @pytest.mark.parametrize("input", ["21-01-01", "01-01-21"]) |
447 | 448 | @pytest.mark.parametrize("yearfirst", [True, False]) |
448 | 449 | def test_parse_datetime_string_with_reso_yearfirst(yearfirst, input): |
449 | | - set_option("display.date_yearfirst", yearfirst) |
450 | | - except_out_dateutil, result = _helper_hypothesis_delimited_date( |
451 | | - parsing.parse_datetime_string_with_reso, input |
452 | | - ) |
453 | | - except_in_dateutil, expected = _helper_hypothesis_delimited_date( |
454 | | - du_parse, |
455 | | - input, |
456 | | - default=datetime(1, 1, 1), |
457 | | - dayfirst=False, |
458 | | - yearfirst=yearfirst, |
459 | | - ) |
460 | | - assert except_out_dateutil == except_in_dateutil |
461 | | - assert result[0] == expected |
| 450 | + with option_context("display.date_yearfirst", yearfirst): |
| 451 | + except_out_dateutil, result = _helper_hypothesis_delimited_date( |
| 452 | + parsing.parse_datetime_string_with_reso, input |
| 453 | + ) |
| 454 | + except_in_dateutil, expected = _helper_hypothesis_delimited_date( |
| 455 | + du_parse, |
| 456 | + input, |
| 457 | + default=datetime(1, 1, 1), |
| 458 | + dayfirst=False, |
| 459 | + yearfirst=yearfirst, |
| 460 | + ) |
| 461 | + assert except_out_dateutil == except_in_dateutil |
| 462 | + assert result[0] == expected |
0 commit comments