Skip to content

Commit b37ec14

Browse files
sinhrksjreback
authored andcommitted
TST/BUG: Added mote tests for Period(NaT) (#13737)
TST/BUG: Added more tests for Period(NaT)
1 parent ae144bb commit b37ec14

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

doc/source/whatsnew/v0.19.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,12 @@ Previous Behavior:
527527

528528
New Behavior:
529529

530+
These result in ``pd.NaT`` without providing ``freq`` option.
531+
530532
.. ipython:: python
531533

532534
pd.Period('NaT')
535+
pd.Period(None)
533536

534537

535538
To be compat with ``Period`` addition and subtraction, ``pd.NaT`` now supports addition and subtraction with ``int``. Previously it raises ``ValueError``.
@@ -549,6 +552,7 @@ New Behavior:
549552
pd.NaT + 1
550553
pd.NaT - 1
551554

555+
552556
.. _whatsnew_0190.api.difference:
553557

554558
``Index.difference`` and ``.symmetric_difference`` changes
@@ -701,6 +705,8 @@ Bug Fixes
701705

702706
- Bug in ``Series`` arithmetic raises ``TypeError`` if it contains datetime-like as ``object`` dtype (:issue:`13043`)
703707

708+
- Bug ``Series.isnull`` and ``Series.notnull`` ignore ``Period('NaT')`` (:issue:`13737`)
709+
- Bug ``Series.fillna`` and ``Series.dropna`` don't affect to ``Period('NaT')`` (:issue:`13737`)
704710

705711
- Bug in ``pd.to_datetime()`` when passing invalid datatypes (e.g. bool); will now respect the ``errors`` keyword (:issue:`13176`)
706712
- Bug in ``pd.to_datetime()`` which overflowed on ``int8``, and ``int16`` dtypes (:issue:`13451`)

pandas/tseries/tests/test_period.py

+30
Original file line numberDiff line numberDiff line change
@@ -4294,6 +4294,36 @@ def test_constructor_cast_object(self):
42944294
exp = Series(period_range('1/1/2000', periods=10))
42954295
tm.assert_series_equal(s, exp)
42964296

4297+
def test_isnull(self):
4298+
# GH 13737
4299+
s = Series([pd.Period('2011-01', freq='M'),
4300+
pd.Period('NaT', freq='M')])
4301+
tm.assert_series_equal(s.isnull(), Series([False, True]))
4302+
tm.assert_series_equal(s.notnull(), Series([True, False]))
4303+
4304+
def test_fillna(self):
4305+
# GH 13737
4306+
s = Series([pd.Period('2011-01', freq='M'),
4307+
pd.Period('NaT', freq='M')])
4308+
4309+
res = s.fillna(pd.Period('2012-01', freq='M'))
4310+
exp = Series([pd.Period('2011-01', freq='M'),
4311+
pd.Period('2012-01', freq='M')])
4312+
tm.assert_series_equal(res, exp)
4313+
self.assertEqual(res.dtype, 'object')
4314+
4315+
res = s.fillna('XXX')
4316+
exp = Series([pd.Period('2011-01', freq='M'), 'XXX'])
4317+
tm.assert_series_equal(res, exp)
4318+
self.assertEqual(res.dtype, 'object')
4319+
4320+
def test_dropna(self):
4321+
# GH 13737
4322+
s = Series([pd.Period('2011-01', freq='M'),
4323+
pd.Period('NaT', freq='M')])
4324+
tm.assert_series_equal(s.dropna(),
4325+
Series([pd.Period('2011-01', freq='M')]))
4326+
42974327
def test_series_comparison_scalars(self):
42984328
val = pd.Period('2000-01-04', freq='D')
42994329
result = self.series > val

0 commit comments

Comments
 (0)