|
1 | 1 | """ test the scalar Timedelta """
|
2 | 2 | from datetime import timedelta
|
| 3 | +import re |
3 | 4 |
|
4 | 5 | import numpy as np
|
5 | 6 | import pytest
|
@@ -317,6 +318,7 @@ def test_nat_converters(self):
|
317 | 318 | assert result.dtype.kind == 'm'
|
318 | 319 | assert result.astype('int64') == iNaT
|
319 | 320 |
|
| 321 | + @pytest.mark.filterwarnings("ignore:M and Y units are deprecated") |
320 | 322 | @pytest.mark.parametrize('units, np_unit',
|
321 | 323 | [(['Y', 'y'], 'Y'),
|
322 | 324 | (['M'], 'M'),
|
@@ -376,6 +378,24 @@ def test_unit_parser(self, units, np_unit, wrapper):
|
376 | 378 | result = Timedelta('2{}'.format(unit))
|
377 | 379 | assert result == expected
|
378 | 380 |
|
| 381 | + @pytest.mark.skipif(compat.PY2, reason="requires python3.5 or higher") |
| 382 | + @pytest.mark.parametrize('unit', ['Y', 'y', 'M']) |
| 383 | + def test_unit_m_y_deprecated(self, unit): |
| 384 | + with tm.assert_produces_warning(FutureWarning) as w1: |
| 385 | + Timedelta(10, unit) |
| 386 | + msg = r'.* units are deprecated .*' |
| 387 | + assert re.match(msg, str(w1[0].message)) |
| 388 | + with tm.assert_produces_warning(FutureWarning, |
| 389 | + check_stacklevel=False) as w2: |
| 390 | + to_timedelta(10, unit) |
| 391 | + msg = r'.* units are deprecated .*' |
| 392 | + assert re.match(msg, str(w2[0].message)) |
| 393 | + with tm.assert_produces_warning(FutureWarning, |
| 394 | + check_stacklevel=False) as w3: |
| 395 | + to_timedelta([1, 2], unit) |
| 396 | + msg = r'.* units are deprecated .*' |
| 397 | + assert re.match(msg, str(w3[0].message)) |
| 398 | + |
379 | 399 | def test_numeric_conversions(self):
|
380 | 400 | assert Timedelta(0) == np.timedelta64(0, 'ns')
|
381 | 401 | assert Timedelta(10) == np.timedelta64(10, 'ns')
|
|
0 commit comments