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..cf99979c47ba 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,9 @@ 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 +117,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..b6f3ebe42726 100644 --- a/pythonFiles/datascience/getJupyterVariableDataFrameRows.py +++ b/pythonFiles/datascience/getJupyterVariableDataFrameRows.py @@ -2,16 +2,19 @@ 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 +49,4 @@ del _VSCODE_json del _VSCODE_pd del _VSCODE_pd_json +del _VSCODE_builtins 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()