Skip to content

Commit 03f0022

Browse files
code sample for pandas-dev#42437
1 parent f6c2d0d commit 03f0022

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

bisect/42437.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# BUG: Assigning extension array value to series of dtype object fails if element type is array-like #42437
2+
3+
import pandas as pd
4+
from pandas.api.extensions import (
5+
ExtensionArray,
6+
ExtensionDtype,
7+
)
8+
9+
print(pd.__version__)
10+
11+
12+
class StubDtype(ExtensionDtype):
13+
"""Extension dtype whose elements are something that numpy.asarray()
14+
will turn into an array (in this case a tuple)"""
15+
16+
def __init__(self):
17+
pass
18+
19+
@property
20+
def type(self):
21+
return tuple
22+
23+
@property
24+
def name(self) -> str:
25+
return "StubDtype"
26+
27+
@classmethod
28+
def construct_array_type(cls):
29+
return StubExtensionArray()
30+
31+
32+
class StubExtensionArray(ExtensionArray):
33+
"""Just enough of an extension array to run the four lines of code
34+
that follow."""
35+
36+
@property
37+
def dtype(self):
38+
return StubDtype()
39+
40+
def copy(self):
41+
return StubExtensionArray()
42+
43+
def __len__(self):
44+
return 5
45+
46+
def __getitem__(self, key):
47+
# Every position in the array has the tuple (1, 2, 3)
48+
return (1, 2, 3)
49+
50+
51+
data = StubExtensionArray()
52+
series1 = pd.Series(data, name="data")
53+
series2 = pd.Series(index=series1.index, dtype=object, name="data")
54+
series2.loc[series1.index] = data

0 commit comments

Comments
 (0)