StyleFrame 对象的深拷贝
deep copy of StyleFrame object
如何制作 StyleFrame 对象的浅拷贝或深拷贝?
当我使用 copy.copy(sf) 或 copy.deepcopy(sf) 时出现错误:
"RecursionError: maximum recursion depth exceeded while calling a Python object"
import copy
from StyleFrame import StyleFrame
import pandas as pd
df=pd.DataFrame([list('abc')])
sf=StyleFrame(df)
copy.copy(sf)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python\python373\lib\copy.py", line 106, in copy
return _reconstruct(x, None, *rv)
File "C:\python\python373\lib\copy.py", line 281, in _reconstruct
if hasattr(y, '__setstate__'):
File "C:\python\python373_vm1\lib\site-packages\StyleFrame\style_frame.py", line 121, in __getattr__
if attr in self.data_df.columns:
File "C:\python\python373_vm1\lib\site-packages\StyleFrame\style_frame.py", line 121, in __getattr__
if attr in self.data_df.columns:
File "C:\python\python373_vm1\lib\site-packages\StyleFrame\style_frame.py", line 121, in __getattr__
if attr in self.data_df.columns:
[Previous line repeated 495 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
只需将原始 StyleFrame 对象传递给 StyleFrame
。在内部,它会深度复制底层数据帧,还会复制一些内部属性。
sf = StyleFrame({'a': [1, 2]})
print(id(sf))
new_sf = StyleFrame(sf)
print(id(new_sf))
产出
1971232017152
1971267198144
如何制作 StyleFrame 对象的浅拷贝或深拷贝? 当我使用 copy.copy(sf) 或 copy.deepcopy(sf) 时出现错误: "RecursionError: maximum recursion depth exceeded while calling a Python object"
import copy
from StyleFrame import StyleFrame
import pandas as pd
df=pd.DataFrame([list('abc')])
sf=StyleFrame(df)
copy.copy(sf)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python\python373\lib\copy.py", line 106, in copy
return _reconstruct(x, None, *rv)
File "C:\python\python373\lib\copy.py", line 281, in _reconstruct
if hasattr(y, '__setstate__'):
File "C:\python\python373_vm1\lib\site-packages\StyleFrame\style_frame.py", line 121, in __getattr__
if attr in self.data_df.columns:
File "C:\python\python373_vm1\lib\site-packages\StyleFrame\style_frame.py", line 121, in __getattr__
if attr in self.data_df.columns:
File "C:\python\python373_vm1\lib\site-packages\StyleFrame\style_frame.py", line 121, in __getattr__
if attr in self.data_df.columns:
[Previous line repeated 495 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
只需将原始 StyleFrame 对象传递给 StyleFrame
。在内部,它会深度复制底层数据帧,还会复制一些内部属性。
sf = StyleFrame({'a': [1, 2]})
print(id(sf))
new_sf = StyleFrame(sf)
print(id(new_sf))
产出
1971232017152
1971267198144