numpy.NaN - python examples

Here are the examples of the python api numpy.NaN taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_astype.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_astype_datetime64(self):
        # GH 13149, GH 13209
        idx = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN])

        result = idx.astype('datetime64[ns]')
        tm.astert_index_equal(result, idx)
        astert result is not idx

        result = idx.astype('datetime64[ns]', copy=False)
        tm.astert_index_equal(result, idx)
        astert result is idx

        idx_tz = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN], tz='EST')
        result = idx_tz.astype('datetime64[ns]')
        expected = DatetimeIndex(['2016-05-16 05:00:00', 'NaT', 'NaT', 'NaT'],
                                 dtype='datetime64[ns]')
        tm.astert_index_equal(result, expected)

3 View Complete Implementation : test_combine_concat.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_combine_first_dt64(self):
        from pandas.core.tools.datetimes import to_datetime
        s0 = to_datetime(Series(["2010", np.NaN]))
        s1 = to_datetime(Series([np.NaN, "2011"]))
        rs = s0.combine_first(s1)
        xp = to_datetime(Series(['2010', '2011']))
        astert_series_equal(rs, xp)

        s0 = to_datetime(Series(["2010", np.NaN]))
        s1 = Series([np.NaN, "2011"])
        rs = s0.combine_first(s1)
        xp = Series([datetime(2010, 1, 1), '2011'])
        astert_series_equal(rs, xp)

3 View Complete Implementation : test_astype.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_astype(self):
        # GH 13149, GH 13209
        idx = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN])

        result = idx.astype(object)
        expected = Index([Timestamp('2016-05-16')] + [NaT] * 3, dtype=object)
        tm.astert_index_equal(result, expected)

        result = idx.astype(int)
        expected = Int64Index([1463356800000000000] +
                              [-9223372036854775808] * 3, dtype=np.int64)
        tm.astert_index_equal(result, expected)

        rng = date_range('1/1/2000', periods=10)
        result = rng.astype('i8')
        tm.astert_index_equal(result, Index(rng.asi8))
        tm.astert_numpy_array_equal(result.values, rng.asi8)

3 View Complete Implementation : test_timezones.py
Copyright Apache License 2.0
Author : Frank-qlu
    @pytest.mark.parametrize('tz', [pytz.timezone('US/Eastern'),
                                    gettz('US/Eastern')])
    def test_dti_tz_localize_ambiguous_nat(self, tz):
        times = ['11/06/2011 00:00', '11/06/2011 01:00', '11/06/2011 01:00',
                 '11/06/2011 02:00', '11/06/2011 03:00']
        di = DatetimeIndex(times)
        localized = di.tz_localize(tz, ambiguous='NaT')

        times = ['11/06/2011 00:00', np.NaN, np.NaN, '11/06/2011 02:00',
                 '11/06/2011 03:00']
        di_test = DatetimeIndex(times, tz='US/Eastern')

        # left dtype is datetime64[ns, US/Eastern]
        # right is datetime64[ns, tzfile('/usr/share/zoneinfo/US/Eastern')]
        tm.astert_numpy_array_equal(di_test.values, localized.values)

3 View Complete Implementation : test_dtypes.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_astype_str_float(self, text_dtype):
        # see gh-11302
        result = DataFrame([np.NaN]).astype(text_dtype)
        expected = DataFrame(["nan"])

        astert_frame_equal(result, expected)
        result = DataFrame([1.12345678901234567890]).astype(text_dtype)

        # < 1.14 truncates
        # >= 1.14 preserves the full repr
        val = ("1.12345678901" if _np_version_under1p14
               else "1.1234567890123457")
        expected = DataFrame([val])
        astert_frame_equal(result, expected)

3 View Complete Implementation : test_astype.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_astype_timedelta64(self):
        # GH 13149, GH 13209
        idx = TimedeltaIndex([1e14, 'NaT', NaT, np.NaN])

        result = idx.astype('timedelta64')
        expected = Float64Index([1e+14] + [np.NaN] * 3, dtype='float64')
        tm.astert_index_equal(result, expected)

        result = idx.astype('timedelta64[ns]')
        tm.astert_index_equal(result, idx)
        astert result is not idx

        result = idx.astype('timedelta64[ns]', copy=False)
        tm.astert_index_equal(result, idx)
        astert result is idx

3 View Complete Implementation : test_timezones.py
Copyright Apache License 2.0
Author : Frank-qlu
    @pytest.mark.parametrize('tz', [pytz.timezone('US/Eastern'),
                                    gettz('US/Eastern')])
    def test_dti_tz_localize_ambiguous_nat(self, tz):
        times = ['11/06/2011 00:00', '11/06/2011 01:00', '11/06/2011 01:00',
                 '11/06/2011 02:00', '11/06/2011 03:00']
        di = DatetimeIndex(times)
        localized = di.tz_localize(tz, ambiguous='NaT')

        times = ['11/06/2011 00:00', np.NaN, np.NaN, '11/06/2011 02:00',
                 '11/06/2011 03:00']
        di_test = DatetimeIndex(times, tz='US/Eastern')

        # left dtype is datetime64[ns, US/Eastern]
        # right is datetime64[ns, tzfile('/usr/share/zoneinfo/US/Eastern')]
        tm.astert_numpy_array_equal(di_test.values, localized.values)

3 View Complete Implementation : test_astype.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_astype(self):
        # GH 13149, GH 13209
        idx = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN])

        result = idx.astype(object)
        expected = Index([Timestamp('2016-05-16')] + [NaT] * 3, dtype=object)
        tm.astert_index_equal(result, expected)

        result = idx.astype(int)
        expected = Int64Index([1463356800000000000] +
                              [-9223372036854775808] * 3, dtype=np.int64)
        tm.astert_index_equal(result, expected)

        rng = date_range('1/1/2000', periods=10)
        result = rng.astype('i8')
        tm.astert_index_equal(result, Index(rng.asi8))
        tm.astert_numpy_array_equal(result.values, rng.asi8)

3 View Complete Implementation : test_combine_concat.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_combine_first_dt64(self):
        from pandas.core.tools.datetimes import to_datetime
        s0 = to_datetime(Series(["2010", np.NaN]))
        s1 = to_datetime(Series([np.NaN, "2011"]))
        rs = s0.combine_first(s1)
        xp = to_datetime(Series(['2010', '2011']))
        astert_series_equal(rs, xp)

        s0 = to_datetime(Series(["2010", np.NaN]))
        s1 = Series([np.NaN, "2011"])
        rs = s0.combine_first(s1)
        xp = Series([datetime(2010, 1, 1), '2011'])
        astert_series_equal(rs, xp)

3 View Complete Implementation : test_astype.py
Copyright Apache License 2.0
Author : Frank-qlu
    def test_astype_timedelta64(self):
        # GH 13149, GH 13209
        idx = TimedeltaIndex([1e14, 'NaT', NaT, np.NaN])

        result = idx.astype('timedelta64')
        expected = Float64Index([1e+14] + [np.NaN] * 3, dtype='float64')
        tm.astert_index_equal(result, expected)

        result = idx.astype('timedelta64[ns]')
        tm.astert_index_equal(result, idx)
        astert result is not idx

        result = idx.astype('timedelta64[ns]', copy=False)
        tm.astert_index_equal(result, idx)
        astert result is idx