forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f726d83
commit 984243e
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |