I have the following example:
import pandas as pd
from copy import copy, deepcopy
class DataFrameWrapper(pd.DataFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __eq__(self, other):
return self.equals(other)
t1 = DataFrameWrapper(pd.DataFrame({'a': [1, 2, 3]}))
t2 = deepcopy(t1)
t3 = copy(t1)
print(type(t1), ' ', type(t2), ' ', type(t3))
Output:
<class 'DataFrameWrapper'> <class 'pandas.core.frame.DataFrame'> <class 'pandas.core.frame.DataFrame'>
Is anyone able to tell me why copy and deepcopy are modifying the type of t1
?
The purpose of the DataFrameWrapper
class is simply to allow me to do a ==
between pandas DataFrames.