Skip to content

Commit

Permalink
Merge pull request #199 from quantopian/fix-edit-unnamed-index
Browse files Browse the repository at this point in the history
Fixing issue with editing a table with unnamed index columns, bumping version again
  • Loading branch information
TimShawver authored Jun 4, 2018
2 parents 2fd7f48 + 60c7df3 commit 42ed3db
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qgrid",
"version": "1.0.3",
"version": "1.0.5",
"description": "An Interactive Grid for Sorting and Filtering DataFrames in Jupyter Notebook",
"author": "Quantopian Inc.",
"main": "src/index.js",
Expand Down
4 changes: 2 additions & 2 deletions js/src/qgrid.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel {
_view_name : 'QgridView',
_model_module : 'qgrid',
_view_module : 'qgrid',
_model_module_version : '^1.0.3',
_view_module_version : '^1.0.3',
_model_module_version : '^1.0.5',
_view_module_version : '^1.0.5',
_df_json: '',
_columns: {}
});
Expand Down
2 changes: 1 addition & 1 deletion qgrid/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_info = (1, 0, 3, 'final')
version_info = (1, 0, 5, 'final')

_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}

Expand Down
9 changes: 5 additions & 4 deletions qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ class QgridWidget(widgets.DOMWidget):
_model_name = Unicode('QgridModel').tag(sync=True)
_view_module = Unicode('qgrid').tag(sync=True)
_model_module = Unicode('qgrid').tag(sync=True)
_view_module_version = Unicode('1.0.3').tag(sync=True)
_model_module_version = Unicode('1.0.3').tag(sync=True)
_view_module_version = Unicode('1.0.5').tag(sync=True)
_model_module_version = Unicode('1.0.5').tag(sync=True)

_df = Instance(pd.DataFrame)
_df_json = Unicode('', sync=True)
Expand Down Expand Up @@ -1220,8 +1220,9 @@ def _handle_qgrid_msg_helper(self, content):
if col_info['type'] == 'datetime':
val_to_set = pd.to_datetime(val_to_set)

old_value = self._df.at[location]
self._df.at[location] = val_to_set
old_value = self._df.loc[location]
self._df.loc[location] = val_to_set

query = self._unfiltered_df[self._index_col_name] == \
content['unfiltered_index']
self._unfiltered_df.loc[query, content['column']] = val_to_set
Expand Down
21 changes: 18 additions & 3 deletions qgrid/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ def test_edit_date():
"2013-01-16T00:00:00.000Z")


def test_edit_multi_index_df():
df_multi = create_multi_index_df()
view = QgridWidget(df=df_multi)
old_val = df_multi.loc[('bar', 'two'), 1]

check_edit_success(view,
1,
1,
old_val,
round(old_val, pd.get_option('display.precision') - 1),
3.45678,
3.45678)


def check_edit_success(widget,
col_name,
row_index,
Expand All @@ -85,7 +99,7 @@ def check_edit_success(widget,
event_history = init_event_history('cell_edited', widget)

grid_data = json.loads(widget._df_json)['data']
assert grid_data[row_index][col_name] == old_val_json
assert grid_data[row_index][str(col_name)] == old_val_json

widget._handle_qgrid_msg_helper({
'column': col_name,
Expand All @@ -95,9 +109,10 @@ def check_edit_success(widget,
'value': new_val_json
})

expected_index_val = widget._df.index[row_index]
assert event_history == [{
'name': 'cell_edited',
'index': row_index,
'index': expected_index_val,
'column': col_name,
'old': old_val_obj,
'new': new_val_obj
Expand All @@ -107,7 +122,7 @@ def check_edit_success(widget,
# call _update_table so the widget updates _df_json
widget._update_table(fire_data_change_event=False)
grid_data = json.loads(widget._df_json)['data']
assert grid_data[row_index][col_name] == new_val_json
assert grid_data[row_index][str(col_name)] == new_val_json


def test_edit_number():
Expand Down

0 comments on commit 42ed3db

Please sign in to comment.