Skip to content

Commit 21a826f

Browse files
committed
improve returned dataframe view
Signed-off-by: Itay Dafna <[email protected]>
1 parent 622a378 commit 21a826f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ipydatagrid/datagrid.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ def data(self):
325325
@data.setter
326326
def data(self, dataframe):
327327
guid_key = "ipydguuid"
328+
# Reference for the original frame column and index names
329+
# This is used to when returning the view data model
330+
self.__dataframe_reference_index_names = dataframe.index.names
331+
self.__dataframe_reference_columns = dataframe.columns
332+
328333
dataframe = dataframe.copy()
329334
dataframe[guid_key] = pd.RangeIndex(0, dataframe.shape[0])
330335
schema = pd.io.json.build_table_schema(dataframe)
@@ -445,6 +450,8 @@ def get_visible_data(self):
445450
at = self._data["schema"]["primaryKey"]
446451
return_df = pd.DataFrame(data["data"]).set_index(at)
447452
return_df.index = return_df.index.droplevel(return_df.index.nlevels - 1)
453+
return_df.index.names = self.__dataframe_reference_index_names
454+
return_df.columns = self.__dataframe_reference_columns
448455
return return_df
449456

450457
def transform(self, transforms):

0 commit comments

Comments
 (0)