From a776b0ce33f28ed50dd42f4946f2239e2cadb95e Mon Sep 17 00:00:00 2001 From: jreback Date: Sat, 19 Jan 2013 23:00:16 -0500 Subject: [PATCH 1/3] DOC: docs for enhancement for using np.nan with datetim64[ns] --- doc/source/v0.10.1.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/source/v0.10.1.txt b/doc/source/v0.10.1.txt index 8aa2dad2b35a0..e4083f745e77e 100644 --- a/doc/source/v0.10.1.txt +++ b/doc/source/v0.10.1.txt @@ -14,6 +14,21 @@ API changes New features ~~~~~~~~~~~~ +Datetime64[ns] columns in a DataFrame (or a Series) allow the use of ``np.nan`` to indicate a nan value, in additional to the traditional ``NaT``, or not-a-time. This allows convenient nan setting in a generic way. Furthermore datetime64 columns are created by default, when using ``datetime.datetime`` or ``Timestamp`` objects, rather than default as object dtype. + +.. ipython:: python + + df = DataFrame(randn(6,2),date_range('20010102',periods=6),columns=['A','B']) + df['timestamp'] = Timestamp('20010103') + df + + # datetime64[ns] out of the box + df.get_dtype_counts() + + # use the traditional nan, which is mapped to NaT internally + df.ix[2:4,['A','timestamp']] = np.nan + df + HDFStore ~~~~~~~~ @@ -59,7 +74,7 @@ You can now store ``datetime64`` in data columns df_mixed = df.copy() df_mixed['datetime64'] = Timestamp('20010102') - df_mixed.ix[3:4,['A','B']] = np.nan + df_mixed.ix[3:4,['A','B','datetime64']] = np.nan store.append('df_mixed', df_mixed) df_mixed1 = store.select('df_mixed') From 44564168ab30d787ed7fb53cb25c8c2a18fe73a4 Mon Sep 17 00:00:00 2001 From: jreback Date: Mon, 21 Jan 2013 09:00:54 -0500 Subject: [PATCH 2/3] CLN: changed datetime64 testing in applymap to use is_datetime64_dtype idiom --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 301ea9d28d001..4c3922d313684 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4287,9 +4287,9 @@ def applymap(self, func): applied : DataFrame """ - # if we have a dtype == 'M8[ns]', provide boxed values + # if we have a datetime64 type, provide boxed values def infer(x): - if x.dtype == 'M8[ns]': + if com.is_datetime64_dtype(x): x = lib.map_infer(x, lib.Timestamp) return lib.map_infer(x, func) return self.apply(infer) From 83cceab68b82c42a96b9e5393e800ceae0d039d2 Mon Sep 17 00:00:00 2001 From: jreback Date: Mon, 21 Jan 2013 21:25:03 -0500 Subject: [PATCH 3/3] DOC: fixed v0.10.1 whatsnew for datetime64[ns] series --- doc/source/v0.10.1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/v0.10.1.txt b/doc/source/v0.10.1.txt index e4083f745e77e..a2b99bf6c4174 100644 --- a/doc/source/v0.10.1.txt +++ b/doc/source/v0.10.1.txt @@ -14,7 +14,7 @@ API changes New features ~~~~~~~~~~~~ -Datetime64[ns] columns in a DataFrame (or a Series) allow the use of ``np.nan`` to indicate a nan value, in additional to the traditional ``NaT``, or not-a-time. This allows convenient nan setting in a generic way. Furthermore datetime64 columns are created by default, when using ``datetime.datetime`` or ``Timestamp`` objects, rather than default as object dtype. +Datetime64[ns] columns in a DataFrame (or a Series) allow the use of ``np.nan`` to indicate a nan value, in addition to the traditional ``NaT``, or not-a-time. This allows convenient nan setting in a generic way. Furthermore datetime64 columns are created by default, when using ``datetime.datetime`` or ``Timestamp`` objects, rather than default as object dtype. .. ipython:: python