@@ -4728,6 +4728,58 @@ def test_to_dict(self):
4728
4728
for k2, v2 in compat.iteritems(v):
4729
4729
self.assertEqual(v2, recons_data[k2][k])
4730
4730
4731
+ def test_to_dict_timestamp(self):
4732
+
4733
+ # GH11247
4734
+ # split/records producing np.datetime64 rather than Timestamps
4735
+ # on datetime64[ns] dtypes only
4736
+
4737
+ tsmp = Timestamp('20130101')
4738
+ test_data = DataFrame({'A': [tsmp, tsmp], 'B': [tsmp, tsmp]})
4739
+ test_data_mixed = DataFrame({'A': [tsmp, tsmp], 'B': [1, 2]})
4740
+
4741
+ expected_records = [{'A': tsmp, 'B': tsmp},
4742
+ {'A': tsmp, 'B': tsmp}]
4743
+ expected_records_mixed = [{'A': tsmp, 'B': 1},
4744
+ {'A': tsmp, 'B': 2}]
4745
+
4746
+ tm.assert_almost_equal(test_data.to_dict(
4747
+ orient='records'), expected_records)
4748
+ tm.assert_almost_equal(test_data_mixed.to_dict(
4749
+ orient='records'), expected_records_mixed)
4750
+
4751
+ expected_series = {
4752
+ 'A': Series([tsmp, tsmp]),
4753
+ 'B': Series([tsmp, tsmp]),
4754
+ }
4755
+ expected_series_mixed = {
4756
+ 'A': Series([tsmp, tsmp]),
4757
+ 'B': Series([1, 2]),
4758
+ }
4759
+
4760
+ tm.assert_almost_equal(test_data.to_dict(
4761
+ orient='series'), expected_series)
4762
+ tm.assert_almost_equal(test_data_mixed.to_dict(
4763
+ orient='series'), expected_series_mixed)
4764
+
4765
+ expected_split = {
4766
+ 'index': [0, 1],
4767
+ 'data': [[tsmp, tsmp],
4768
+ [tsmp, tsmp]],
4769
+ 'columns': ['A', 'B']
4770
+ }
4771
+ expected_split_mixed = {
4772
+ 'index': [0, 1],
4773
+ 'data': [[tsmp, 1],
4774
+ [tsmp, 2]],
4775
+ 'columns': ['A', 'B']
4776
+ }
4777
+
4778
+ tm.assert_almost_equal(test_data.to_dict(
4779
+ orient='split'), expected_split)
4780
+ tm.assert_almost_equal(test_data_mixed.to_dict(
4781
+ orient='split'), expected_split_mixed)
4782
+
4731
4783
def test_to_dict_invalid_orient(self):
4732
4784
df = DataFrame({'A':[0, 1]})
4733
4785
self.assertRaises(ValueError, df.to_dict, orient='xinvalid')
0 commit comments