Skip to content

TST/BUG: Added more tests for Period(NaT) #13737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/source/whatsnew/v0.19.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,12 @@ Previous Behavior:

New Behavior:

These result in ``pd.NaT`` without providing ``freq`` option.

.. ipython:: python

pd.Period('NaT')
pd.Period(None)


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


.. _whatsnew_0190.api.difference:

``Index.difference`` and ``.symmetric_difference`` changes
Expand Down Expand Up @@ -701,6 +705,8 @@ Bug Fixes

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

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

- Bug in ``pd.to_datetime()`` when passing invalid datatypes (e.g. bool); will now respect the ``errors`` keyword (:issue:`13176`)
- Bug in ``pd.to_datetime()`` which overflowed on ``int8``, and ``int16`` dtypes (:issue:`13451`)
Expand Down
30 changes: 30 additions & 0 deletions pandas/tseries/tests/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -4294,6 +4294,36 @@ def test_constructor_cast_object(self):
exp = Series(period_range('1/1/2000', periods=10))
tm.assert_series_equal(s, exp)

def test_isnull(self):
# GH 13737
s = Series([pd.Period('2011-01', freq='M'),
pd.Period('NaT', freq='M')])
tm.assert_series_equal(s.isnull(), Series([False, True]))
tm.assert_series_equal(s.notnull(), Series([True, False]))

def test_fillna(self):
# GH 13737
s = Series([pd.Period('2011-01', freq='M'),
pd.Period('NaT', freq='M')])

res = s.fillna(pd.Period('2012-01', freq='M'))
exp = Series([pd.Period('2011-01', freq='M'),
pd.Period('2012-01', freq='M')])
tm.assert_series_equal(res, exp)
self.assertEqual(res.dtype, 'object')

res = s.fillna('XXX')
exp = Series([pd.Period('2011-01', freq='M'), 'XXX'])
tm.assert_series_equal(res, exp)
self.assertEqual(res.dtype, 'object')

def test_dropna(self):
# GH 13737
s = Series([pd.Period('2011-01', freq='M'),
pd.Period('NaT', freq='M')])
tm.assert_series_equal(s.dropna(),
Series([pd.Period('2011-01', freq='M')]))

def test_series_comparison_scalars(self):
val = pd.Period('2000-01-04', freq='D')
result = self.series > val
Expand Down