Example #1
0
def test_nat_parse(all_parsers):
    # see gh-3062
    parser = all_parsers
    df = DataFrame(dict({"A": np.asarray(lrange(10), dtype="float64"),
                         "B": pd.Timestamp("20010101")}))
    df.iloc[3:6, :] = np.nan

    with tm.ensure_clean("__nat_parse_.csv") as path:
        df.to_csv(path)

        result = parser.read_csv(path, index_col=0, parse_dates=["B"])
        tm.assert_frame_equal(result, df)
Example #2
0
def test_nan_to_nat_conversions():

    df = DataFrame(dict({
        'A': np.asarray(range(10), dtype='float64'),
        'B': Timestamp('20010101')
    }))
    df.iloc[3:6, :] = np.nan
    result = df.loc[4, 'B'].value
    assert (result == iNaT)

    s = df['B'].copy()
    s._data = s._data.setitem(indexer=tuple([slice(8, 9)]), value=np.nan)
    assert (isna(s[8]))

    assert (s[8].value == np.datetime64('NaT').astype(np.int64))
Example #3
0
def test_nan_to_nat_conversions():

    df = DataFrame(dict({"A": np.asarray(lrange(10), dtype="float64"), "B": Timestamp("20010101")}))
    df.iloc[3:6, :] = np.nan
    result = df.loc[4, "B"].value
    assert result == iNaT

    s = df["B"].copy()
    s._data = s._data.setitem(tuple([slice(8, 9)]), np.nan)
    assert isnull(s[8])

    # numpy < 1.7.0 is wrong
    from distutils.version import LooseVersion

    if LooseVersion(np.__version__) >= "1.7.0":
        assert s[8].value == np.datetime64("NaT").astype(np.int64)
Example #4
0
def test_nan_to_nat_conversions():

    df = DataFrame(dict({
        'A' : np.asarray(lrange(10),dtype='float64'),
        'B' : Timestamp('20010101') }))
    df.iloc[3:6,:] = np.nan
    result = df.loc[4,'B'].value
    assert(result == iNaT)

    s = df['B'].copy()
    s._data = s._data.setitem(indexer=tuple([slice(8,9)]),value=np.nan)
    assert(isnull(s[8]))

    # numpy < 1.7.0 is wrong
    from distutils.version import LooseVersion
    if LooseVersion(np.__version__) >= '1.7.0':
        assert(s[8].value == np.datetime64('NaT').astype(np.int64))
Example #5
0
def test_nan_to_nat_conversions():

    df = DataFrame(dict({
        'A' : np.asarray(range(10),dtype='float64'),
        'B' : Timestamp('20010101') }))
    df.iloc[3:6,:] = np.nan
    result = df.loc[4,'B'].value
    assert(result == iNaT)

    values = df['B'].values
    result, changed = com._maybe_upcast_indexer(values,tuple([slice(8,9)]),np.nan)
    assert(isnull(result[8]))

    # numpy < 1.7.0 is wrong
    from distutils.version import LooseVersion
    if LooseVersion(np.__version__) >= '1.7.0':
        assert(result[8] == np.datetime64('NaT'))
Example #6
0
    def test_nat_parse(self):
        # See gh-3062
        df = DataFrame(dict({
            'A': np.asarray(lrange(10), dtype='float64'),
            'B': pd.Timestamp('20010101')}))
        df.iloc[3:6, :] = np.nan

        with tm.ensure_clean('__nat_parse_.csv') as path:
            df.to_csv(path)
            result = self.read_csv(path, index_col=0, parse_dates=['B'])
            tm.assert_frame_equal(result, df)

            expected = Series(dict(A='float64', B='datetime64[ns]'))
            tm.assert_series_equal(expected, result.dtypes)

            # test with NaT for the nan_rep
            # we don't have a method to specif the Datetime na_rep (it defaults
            # to '')
            df.to_csv(path)
            result = self.read_csv(path, index_col=0, parse_dates=['B'])
            tm.assert_frame_equal(result, df)