Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/10280.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix problem with Data Viewer not working when builtin functions are overridden (like max).
12 changes: 8 additions & 4 deletions pythonFiles/datascience/getJupyterVariableDataFrameInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']"
Expand All @@ -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

Expand All @@ -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"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also use builtins in VariableList and VariableValue. I'd think it would be safer to do the same thing in those files as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those files aren't used anymore

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could just delete them I guess.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually they're still used to get variables in our ipython tests. But they don't need the update. They're just used to test the other two files. Maybe I should move them instead to the test directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I forgot they were not used anymore. Just saw them when searching for other builtins.


# Figure out shape if not already there. Use the shape to compute the row count
_VSCODE_targetVariable["rowCount"] = _VSCODE_getRowCount(_VSCODE_evalResult)
Expand Down Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down Expand Up @@ -114,3 +117,4 @@ def _VSCODE_getRowCount(var):
del _VSCODE_json
del _VSCODE_pd
del _VSCODE_pd_json
del _VSCODE_builtins
10 changes: 7 additions & 3 deletions pythonFiles/datascience/getJupyterVariableDataFrameRows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,3 +49,4 @@
del _VSCODE_json
del _VSCODE_pd
del _VSCODE_pd_json
del _VSCODE_builtins
8 changes: 2 additions & 6 deletions pythonFiles/tests/ipython/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down