Skip to content

Commit b32e7b6

Browse files
code sample for pandas-dev#43351
1 parent aee852e commit b32e7b6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

bisect/43351.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# BUG: Inconsistent assignment of NAT values to datetime columns in MultiIndex #43351
2+
3+
import numpy as np
4+
5+
import pandas as pd
6+
7+
print(pd.__version__)
8+
9+
midx = pd.MultiIndex(
10+
[
11+
["a", "b", "c"],
12+
["house", "store", "forest"],
13+
["clouds", "clear", "storm"],
14+
["fire", "smoke", "clear"],
15+
[
16+
np.datetime64("2001-01-01", "ns"),
17+
np.datetime64("2002-01-01", "ns"),
18+
np.datetime64("2003-01-01", "ns"),
19+
],
20+
[1.0, np.nan, 2],
21+
],
22+
[
23+
[0, 0, 0, 0, 1, 1, 2],
24+
[1, 1, 1, 1, 0, 0, 2],
25+
[0, 0, 2, 2, 2, 0, 1],
26+
[0, 0, 0, 1, 2, 0, 1],
27+
[1, 0, 1, 2, 0, 0, 1],
28+
[1, 0, 1, 2, 0, 0, 1],
29+
],
30+
)
31+
midx.names = ["alpha", "location", "weather", "sign", "timestamp", "float"]
32+
pdf = pd.DataFrame(
33+
{"a": [1], "b": [2], "c": [3], "d": [2], "e": [0], "f": [2], "g": [10]}
34+
)
35+
pdf.columns = midx
36+
pdf["new_col"] = [11]
37+
38+
result = pdf["new_col"]
39+
print(result)
40+
41+
expected = pd.Series([11], dtype=np.int64, name="new_col")
42+
pd.testing.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)