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_datetime.py
Copyright MIT License
Author : alvarob96
def test_series_set_value():
    # #1561

    dates = [datetime(2001, 1, 1), datetime(2001, 1, 2)]
    index = DatetimeIndex(dates)

    with tm.astert_produces_warning(FutureWarning,
                                    check_stacklevel=False):
        s = Series().set_value(dates[0], 1.)
    with tm.astert_produces_warning(FutureWarning,
                                    check_stacklevel=False):
        s2 = s.set_value(dates[1], np.nan)

    exp = Series([1., np.nan], index=index)

    astert_series_equal(s2, exp)

3 View Complete Implementation : test_calibration.py
Copyright MIT License
Author : alvarob96
def test_calibration_nan_imputer():
    """Test that calibration can accept nan"""
    X, y = make_clastification(n_samples=10, n_features=2,
                               n_informative=2, n_redundant=0,
                               random_state=42)
    X[0, 0] = np.nan
    clf = Pipeline(
        [('imputer', Imputer()),
         ('rf', RandomForestClastifier(n_estimators=1))])
    clf_c = CalibratedClastifierCV(clf, cv=2, method='isotonic')
    clf_c.fit(X, y)
    clf_c.predict(X)

3 View Complete Implementation : test_combine_concat.py
Copyright MIT License
Author : alvarob96
    def test_concat_different_fill(self):
        val1 = np.array([1, 2, np.nan, np.nan, 0, np.nan])
        val2 = np.array([3, np.nan, 4, 0, 0])

        for kind in ['integer', 'block']:
            sparse1 = pd.SparseSeries(val1, name='x', kind=kind)
            sparse2 = pd.SparseSeries(val2, name='y', kind=kind, fill_value=0)

            res = pd.concat([sparse1, sparse2])
            exp = pd.concat([pd.Series(val1), pd.Series(val2)])
            exp = pd.SparseSeries(exp, kind=kind)
            tm.astert_sp_series_equal(res, exp)

            res = pd.concat([sparse2, sparse1])
            exp = pd.concat([pd.Series(val2), pd.Series(val1)])
            exp = pd.SparseSeries(exp, kind=kind, fill_value=0)
            tm.astert_sp_series_equal(res, exp)

3 View Complete Implementation : test_missing.py
Copyright MIT License
Author : alvarob96
    def test_interp_combo(self):
        df = DataFrame({'A': [1., 2., np.nan, 4.],
                        'B': [1, 4, 9, np.nan],
                        'C': [1, 2, 3, 5],
                        'D': list('abcd')})

        result = df['A'].interpolate()
        expected = Series([1., 2., 3., 4.], name='A')
        astert_series_equal(result, expected)

        result = df['A'].interpolate(downcast='infer')
        expected = Series([1, 2, 3, 4], name='A')
        astert_series_equal(result, expected)

3 View Complete Implementation : test_utils.py
Copyright MIT License
Author : alvarob96
    def test_equal_nan_default(self):
        # Make sure equal_nan default behavior remains unchanged. (All
        # of these functions use astert_array_compare under the hood.)
        # None of these should raise.
        a = np.array([np.nan])
        b = np.array([np.nan])
        astert_array_equal(a, b)
        astert_array_almost_equal(a, b)
        astert_array_less(a, b)
        astert_allclose(a, b)

3 View Complete Implementation : test_alter_index.py
Copyright MIT License
Author : alvarob96
def test_reindex_like(test_data):
    other = test_data.ts[::2]
    astert_series_equal(test_data.ts.reindex(other.index),
                        test_data.ts.reindex_like(other))

    # GH 7179
    day1 = datetime(2013, 3, 5)
    day2 = datetime(2013, 5, 5)
    day3 = datetime(2014, 3, 5)

    series1 = Series([5, None, None], [day1, day2, day3])
    series2 = Series([None, None], [day1, day3])

    result = series1.reindex_like(series2, method='pad')
    expected = Series([5, np.nan], index=[day1, day3])
    astert_series_equal(result, expected)

3 View Complete Implementation : test_nanfunctions.py
Copyright MIT License
Author : alvarob96
    def test_allnans(self):
        # Check for FutureWarning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            res = np.nansum([np.nan]*3, axis=None)
            astert_(res == 0, 'result is not 0')
            astert_(len(w) == 0, 'warning raised')
            # Check scalar
            res = np.nansum(np.nan)
            astert_(res == 0, 'result is not 0')
            astert_(len(w) == 0, 'warning raised')
            # Check there is no warning for not all-nan
            np.nansum([0]*3, axis=None)
            astert_(len(w) == 0, 'unwanted warning raised')

3 View Complete Implementation : test_minpack.py
Copyright MIT License
Author : alvarob96
    def test_NaN_handling(self):
        # Test for correct handling of NaNs in input data: gh-3422

        # create input with NaNs
        xdata = np.array([1, np.nan, 3])
        ydata = np.array([1, 2, 3])

        astert_raises(ValueError, curve_fit,
                      lambda x, a, b: a*x + b, xdata, ydata)
        astert_raises(ValueError, curve_fit,
                      lambda x, a, b: a*x + b, ydata, xdata)

        astert_raises(ValueError, curve_fit, lambda x, a, b: a*x + b,
                      xdata, ydata, **{"check_finite": True})

3 View Complete Implementation : test_nat.py
Copyright MIT License
Author : alvarob96
@pytest.mark.parametrize('klast', [Timestamp, Timedelta, Period])
def test_equality(klast):

    # nat
    if klast is not Period:
        klast('').value == iNaT
    klast('nat').value == iNaT
    klast('NAT').value == iNaT
    klast(None).value == iNaT
    klast(np.nan).value == iNaT
    astert isna(klast('nat'))

3 View Complete Implementation : test_indexing.py
Copyright MIT License
Author : alvarob96
    def test_take_fill_value(self):
        orig = pd.Series([1, np.nan, 0, 3, 0],
                         index=list('ABCDE'))
        sparse = orig.to_sparse(fill_value=0)

        tm.astert_sp_series_equal(sparse.take([0]),
                                  orig.take([0]).to_sparse(fill_value=0))

        exp = orig.take([0, 1, 3]).to_sparse(fill_value=0)
        tm.astert_sp_series_equal(sparse.take([0, 1, 3]), exp)

        exp = orig.take([-1, -2]).to_sparse(fill_value=0)
        tm.astert_sp_series_equal(sparse.take([-1, -2]), exp)