Skip to content

Commit 984243e

Browse files
code sample for pandas-dev#42501
1 parent f726d83 commit 984243e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

bisect/42501.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# BUG: extraneous copy of extension arrays in v1.3.0 #42501
2+
3+
import pandas as pd
4+
from pandas.core.arrays.integer import coerce_to_array
5+
6+
print(pd.__version__)
7+
8+
import pandas as pd
9+
10+
11+
class IntegerArrayNoCopy(pd.core.arrays.IntegerArray):
12+
@classmethod
13+
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
14+
values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
15+
return IntegerArrayNoCopy(values, mask)
16+
17+
def copy(self):
18+
raise NotImplementedError
19+
20+
21+
class Int16DtypeNoCopy(pd.Int16Dtype):
22+
@classmethod
23+
def construct_array_type(cls):
24+
return IntegerArrayNoCopy
25+
26+
27+
df = pd.DataFrame({"col": [1, 4, None, 5]}, dtype=object)
28+
result = df.astype({"col": Int16DtypeNoCopy()}, copy=False)
29+
print(result)

0 commit comments

Comments
 (0)