@@ -4728,6 +4728,55 @@ 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
+ # GH11247
4733
+ tsmp = Timestamp('20130101')
4734
+ test_data = DataFrame({'A': [tsmp, tsmp], 'B': [tsmp, tsmp]})
4735
+ test_data_mixed = DataFrame({'A': [tsmp, tsmp], 'B': [1, 2]})
4736
+
4737
+ expected_records = [{'A': tsmp, 'B': tsmp},
4738
+ {'A': tsmp, 'B': tsmp}]
4739
+ expected_records_mixed = [{'A': tsmp, 'B': 1},
4740
+ {'A': tsmp, 'B': 2}]
4741
+
4742
+ tm.assert_almost_equal(test_data.to_dict(
4743
+ orient='records'), expected_records)
4744
+ tm.assert_almost_equal(test_data_mixed.to_dict(
4745
+ orient='records'), expected_records_mixed)
4746
+
4747
+ expected_series = {
4748
+ 'A': Series([tsmp, tsmp]),
4749
+ 'B': Series([tsmp, tsmp]),
4750
+ }
4751
+ expected_series_mixed = {
4752
+ 'A': Series([tsmp, tsmp]),
4753
+ 'B': Series([1, 2]),
4754
+ }
4755
+
4756
+ tm.assert_almost_equal(test_data.to_dict(
4757
+ orient='series'), expected_series)
4758
+ tm.assert_almost_equal(test_data_mixed.to_dict(
4759
+ orient='series'), expected_series_mixed)
4760
+
4761
+ expected_split = {
4762
+ 'index': [0, 1],
4763
+ 'data': [[tsmp, tsmp],
4764
+ [tsmp, tsmp]],
4765
+ 'columns': ['A', 'B']
4766
+ }
4767
+ expected_split_mixed = {
4768
+ 'index': [0, 1],
4769
+ 'data': [[tsmp, 1],
4770
+ [tsmp, 2]],
4771
+ 'columns': ['A', 'B']
4772
+ }
4773
+
4774
+ tm.assert_almost_equal(test_data.to_dict(
4775
+ orient='split'), expected_split)
4776
+ tm.assert_almost_equal(test_data_mixed.to_dict(
4777
+ orient='split'), expected_split_mixed)
4778
+
4779
+
4731
4780
def test_to_dict_invalid_orient(self):
4732
4781
df = DataFrame({'A':[0, 1]})
4733
4782
self.assertRaises(ValueError, df.to_dict, orient='xinvalid')
0 commit comments