From 0bf555246a507c697428ffca3d19320b6ce6a20c Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Tue, 10 Mar 2020 13:47:59 -0700 Subject: [PATCH 1/3] Fix builtins --- news/2 Fixes/10280.md | 1 + .../datascience/getJupyterVariableDataFrameInfo.py | 10 ++++++---- .../datascience/getJupyterVariableDataFrameRows.py | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 news/2 Fixes/10280.md diff --git a/news/2 Fixes/10280.md b/news/2 Fixes/10280.md new file mode 100644 index 000000000000..64b59bc50cad --- /dev/null +++ b/news/2 Fixes/10280.md @@ -0,0 +1 @@ +Fix problem with Data Viewer not working when builtin functions are overridden (like max). \ No newline at end of file diff --git a/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py b/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py index 6a2a2bba9a0f..3b71f94eacd8 100644 --- a/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py +++ b/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py @@ -2,6 +2,7 @@ import json as _VSCODE_json import pandas as _VSCODE_pd import pandas.io.json as _VSCODE_pd_json +import builtins as _VSCODE_builtins # _VSCode_sub_supportsDataExplorer will contain our list of data explorer supported types _VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']" @@ -21,7 +22,7 @@ def _VSCODE_getRowCount(var): return 0 elif hasattr(var, "__len__"): try: - return len(var) + return _VSCODE_builtins.len(var) except TypeError: return 0 @@ -34,7 +35,7 @@ def _VSCODE_getRowCount(var): del _VSCODE_targetVariable else: del _VSCode_supportsDataExplorer - _VSCODE_evalResult = eval(_VSCODE_targetVariable["name"]) + _VSCODE_evalResult = _VSCODE_builtins.eval(_VSCODE_targetVariable["name"]) # Figure out shape if not already there. Use the shape to compute the row count _VSCODE_targetVariable["rowCount"] = _VSCODE_getRowCount(_VSCODE_evalResult) @@ -76,7 +77,7 @@ def _VSCODE_getRowCount(var): # Compute the index column. It may have been renamed _VSCODE_indexColumn = _VSCODE_df.index.name if _VSCODE_df.index.name else "index" - _VSCODE_columnTypes = list(_VSCODE_df.dtypes) + _VSCODE_columnTypes = _VSCODE_builtins.list(_VSCODE_df.dtypes) del _VSCODE_df # Make sure the index column exists @@ -86,7 +87,7 @@ def _VSCODE_getRowCount(var): # Then loop and generate our output json _VSCODE_columns = [] - for _VSCODE_n in range(0, len(_VSCODE_columnNames)): + for _VSCODE_n in _VSCODE_builtins.range(0, _VSCODE_builtins.len(_VSCODE_columnNames)): _VSCODE_column_type = _VSCODE_columnTypes[_VSCODE_n] _VSCODE_column_name = str(_VSCODE_columnNames[_VSCODE_n]) _VSCODE_colobj = {} @@ -114,3 +115,4 @@ def _VSCODE_getRowCount(var): del _VSCODE_json del _VSCODE_pd del _VSCODE_pd_json + del _VSCODE_builtins diff --git a/pythonFiles/datascience/getJupyterVariableDataFrameRows.py b/pythonFiles/datascience/getJupyterVariableDataFrameRows.py index 697cc14ad1b6..84f3fd2ce7f1 100644 --- a/pythonFiles/datascience/getJupyterVariableDataFrameRows.py +++ b/pythonFiles/datascience/getJupyterVariableDataFrameRows.py @@ -2,16 +2,17 @@ import json as _VSCODE_json import pandas as _VSCODE_pd import pandas.io.json as _VSCODE_pd_json +import builtins as _VSCODE_builtins # In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable # Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable _VSCODE_targetVariable = _VSCODE_json.loads("""_VSCode_JupyterTestValue""") -_VSCODE_evalResult = eval(_VSCODE_targetVariable["name"]) +_VSCODE_evalResult = _VSCODE_builtins.eval(_VSCODE_targetVariable["name"]) # _VSCode_JupyterStartRow and _VSCode_JupyterEndRow should be replaced dynamically with the literals # for our start and end rows -_VSCODE_startRow = max(_VSCode_JupyterStartRow, 0) -_VSCODE_endRow = min(_VSCode_JupyterEndRow, _VSCODE_targetVariable["rowCount"]) +_VSCODE_startRow = _VSCODE_builtins.max(_VSCode_JupyterStartRow, 0) +_VSCODE_endRow = _VSCODE_builtins.min(_VSCode_JupyterEndRow, _VSCODE_targetVariable["rowCount"]) # Assume we have a dataframe. If not, turn our eval result into a dataframe _VSCODE_df = _VSCODE_evalResult @@ -46,3 +47,4 @@ del _VSCODE_json del _VSCODE_pd del _VSCODE_pd_json +del _VSCODE_builtins From 976debaa9710e642cc8a290bad017ac91984373c Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Tue, 10 Mar 2020 14:17:52 -0700 Subject: [PATCH 2/3] Format with black --- pythonFiles/datascience/getJupyterVariableDataFrameInfo.py | 4 +++- pythonFiles/datascience/getJupyterVariableDataFrameRows.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py b/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py index 3b71f94eacd8..cf99979c47ba 100644 --- a/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py +++ b/pythonFiles/datascience/getJupyterVariableDataFrameInfo.py @@ -87,7 +87,9 @@ def _VSCODE_getRowCount(var): # Then loop and generate our output json _VSCODE_columns = [] - for _VSCODE_n in _VSCODE_builtins.range(0, _VSCODE_builtins.len(_VSCODE_columnNames)): + for _VSCODE_n in _VSCODE_builtins.range( + 0, _VSCODE_builtins.len(_VSCODE_columnNames) + ): _VSCODE_column_type = _VSCODE_columnTypes[_VSCODE_n] _VSCODE_column_name = str(_VSCODE_columnNames[_VSCODE_n]) _VSCODE_colobj = {} diff --git a/pythonFiles/datascience/getJupyterVariableDataFrameRows.py b/pythonFiles/datascience/getJupyterVariableDataFrameRows.py index 84f3fd2ce7f1..b6f3ebe42726 100644 --- a/pythonFiles/datascience/getJupyterVariableDataFrameRows.py +++ b/pythonFiles/datascience/getJupyterVariableDataFrameRows.py @@ -12,7 +12,9 @@ # _VSCode_JupyterStartRow and _VSCode_JupyterEndRow should be replaced dynamically with the literals # for our start and end rows _VSCODE_startRow = _VSCODE_builtins.max(_VSCode_JupyterStartRow, 0) -_VSCODE_endRow = _VSCODE_builtins.min(_VSCode_JupyterEndRow, _VSCODE_targetVariable["rowCount"]) +_VSCODE_endRow = _VSCODE_builtins.min( + _VSCode_JupyterEndRow, _VSCODE_targetVariable["rowCount"] +) # Assume we have a dataframe. If not, turn our eval result into a dataframe _VSCODE_df = _VSCODE_evalResult From 7445677204df992c7d965d676b6d5e613163f7ab Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Tue, 10 Mar 2020 15:10:28 -0700 Subject: [PATCH 3/3] Move variable value and variable list to just be for tests --- .../ipython}/getJupyterVariableList.py | 0 .../ipython}/getJupyterVariableValue.py | 0 pythonFiles/tests/ipython/scripts.py | 8 ++------ 3 files changed, 2 insertions(+), 6 deletions(-) rename pythonFiles/{datascience => tests/ipython}/getJupyterVariableList.py (100%) rename pythonFiles/{datascience => tests/ipython}/getJupyterVariableValue.py (100%) diff --git a/pythonFiles/datascience/getJupyterVariableList.py b/pythonFiles/tests/ipython/getJupyterVariableList.py similarity index 100% rename from pythonFiles/datascience/getJupyterVariableList.py rename to pythonFiles/tests/ipython/getJupyterVariableList.py diff --git a/pythonFiles/datascience/getJupyterVariableValue.py b/pythonFiles/tests/ipython/getJupyterVariableValue.py similarity index 100% rename from pythonFiles/datascience/getJupyterVariableValue.py rename to pythonFiles/tests/ipython/getJupyterVariableValue.py diff --git a/pythonFiles/tests/ipython/scripts.py b/pythonFiles/tests/ipython/scripts.py index 4fe5c8473485..b36ee07ff430 100644 --- a/pythonFiles/tests/ipython/scripts.py +++ b/pythonFiles/tests/ipython/scripts.py @@ -45,9 +45,7 @@ def execute_script(file, replace_dict=dict([])): def get_variables(capsys): path = os.path.dirname(os.path.abspath(__file__)) - file = os.path.abspath( - os.path.join(path, "../../datascience/getJupyterVariableList.py") - ) + file = os.path.abspath(os.path.join(path, "./getJupyterVariableList.py")) if execute_script(file): read_out = capsys.readouterr() return json.loads(read_out.out) @@ -64,9 +62,7 @@ def find_variable_json(varList, varName): def get_variable_value(variables, name, capsys): varJson = find_variable_json(variables, name) path = os.path.dirname(os.path.abspath(__file__)) - file = os.path.abspath( - os.path.join(path, "../../datascience/getJupyterVariableValue.py") - ) + file = os.path.abspath(os.path.join(path, "./getJupyterVariableValue.py")) keys = dict([("_VSCode_JupyterTestValue", json.dumps(varJson))]) if execute_script(file, keys): read_out = capsys.readouterr()