The greatest quirk in the DataFrameField class comes from the fact that the
Pandas DataFrame instances are coerced to a python dictionary via
df.to_dict("list")
as soon as it is bound to a MongoEngine.Document instance, and likewise
a new Pandas DataFram instance is created from the stored dict
when it is retrieved via dot notation.
As result, when it is retrieved from document class via dot notation, a different instance is returned.
For example:
import pandas as pd
from mongoengine import Document
class my_doc(Document)
df = DataFrameField()
# CREATE THE INVENTORY REQUEST DataFrame
df1 = pd.DataFrame({
'goods': ['a', 'a', 'b', 'b', 'b'],
'stock': [5, 10, 30, 40, 10],
'category': ['c1', 'c2', 'c1', 'c2', 'c1'],
'date': pd.to_datetime(['2014-01-01', '2014-02-01', '2014-01-06', '2014-02-09', '2014-03-09'])
})
doc_inst = my_doc()
doc_inst.df = df1
df2 = doc_inst.df
print(df1 is df2)
#> False -- df1 and df2 are two separate Pandas DataFrame instances