Skip to content

Commit a25405a

Browse files
committed
rebased
1 parent 5686152 commit a25405a

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

doc/source/whatsnew/v0.16.2.txt

+3
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,8 @@ Bug Fixes
8888
- Bug where infer_freq infers timerule (WOM-5XXX) unsupported by to_offset (:issue:`9425`)
8989

9090
- Bug to handle masking empty ``DataFrame``(:issue:`10126`)
91+
9192
- Bug where MySQL interface could not handle numeric table/column names (:issue:`10255`)
9293

94+
- Bug in ``DataFrame`` construction from nested ``dict`` with ``datetime64`` (:issue:`10160`)
95+

pandas/core/frame.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5095,8 +5095,9 @@ def _homogenize(data, index, dtype=None):
50955095
v = v.reindex(index, copy=False)
50965096
else:
50975097
if isinstance(v, dict):
5098-
if oindex is None:
5099-
oindex = index.astype('O')
5098+
if lib.infer_dtype(v) in ['datetime64']:
5099+
v = {lib.Timestamp(key): v[key] for key in v}
5100+
oindex = index.astype('O')
51005101
if type(v) == dict:
51015102
# fast cython method
51025103
v = lib.fast_multiget(v, oindex.values, default=NA)

pandas/tests/test_frame.py

+17
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,23 @@ def test_constructor_dict_multiindex(self):
29542954
df = df.reindex(columns=expected.columns, index=expected.index)
29552955
check(df, expected)
29562956

2957+
def test_constructor_dict_datetime64_index(self):
2958+
2959+
data = {1: {np.datetime64('1990-03-15'): 1},
2960+
2: {np.datetime64('1989-12-03'): 3},
2961+
3: {np.datetime64('1988-11-06'): 5},
2962+
4: {np.datetime64('1984-02-19'): 7}}
2963+
2964+
data_expected = {1: {Timestamp('1990-03-15'): 1},
2965+
2: {Timestamp('1989-12-03'): 3},
2966+
3: {Timestamp('1988-11-06'): 5},
2967+
4: {Timestamp('1984-02-19'): 7}}
2968+
2969+
result = DataFrame(data)
2970+
expected = DataFrame(data_expected)
2971+
assert_frame_equal(result, expected)
2972+
2973+
29572974
def _check_basic_constructor(self, empty):
29582975
"mat: 2d matrix with shpae (3, 2) to input. empty - makes sized objects"
29592976
mat = empty((2, 3), dtype=float)

0 commit comments

Comments
 (0)