Skip to content

Commit

Permalink
code sample for pandas-dev#42501
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins committed Jul 16, 2021
1 parent f726d83 commit 984243e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bisect/42501.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# BUG: extraneous copy of extension arrays in v1.3.0 #42501

import pandas as pd
from pandas.core.arrays.integer import coerce_to_array

print(pd.__version__)

import pandas as pd


class IntegerArrayNoCopy(pd.core.arrays.IntegerArray):
@classmethod
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
return IntegerArrayNoCopy(values, mask)

def copy(self):
raise NotImplementedError


class Int16DtypeNoCopy(pd.Int16Dtype):
@classmethod
def construct_array_type(cls):
return IntegerArrayNoCopy


df = pd.DataFrame({"col": [1, 4, None, 5]}, dtype=object)
result = df.astype({"col": Int16DtypeNoCopy()}, copy=False)
print(result)

0 comments on commit 984243e

Please sign in to comment.