Skip to content

Commit e7a646f

Browse files
code sample for pandas-dev#45311
1 parent 9f4660d commit e7a646f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bisect/45311.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# BUG: "replace" does not work with different numpy-int types even when values are the same #45311
2+
3+
import numpy as np
4+
import pandas as pd
5+
6+
print(pd.__version__)
7+
8+
maps = pd.Series(
9+
[np.int64(0), np.int64(2), np.int64(1)]
10+
) # index-value should be mapped to series-value
11+
map_dict = {old: new for (old, new) in zip(maps.values, maps.index)}
12+
13+
labs = pd.Series([1, 1, 1, 0, 0, 2, 2, 2]).astype(
14+
np.int32
15+
) # Simulate a list of observations
16+
17+
result = labs.replace(map_dict)
18+
print(result)
19+
20+
# test against old incorrect behaviour to find commit that fixes
21+
pd.testing.assert_series_equal(result, labs)

0 commit comments

Comments
 (0)