Open darwin-cai opened 2 years ago
I have fixed the error by editing the source file "spyder/plugins/variableexplorer/widgets/arrayeditor.py" after line 718. After adding the code within elif data.ndim == 3:
to elif is_masked_array:
, detailed changes are as follows:
in script arrayeditor.py start line: 712
elif is_masked_array:
self.stack.addWidget(ArrayEditorWidget(self, data, readonly,
xlabels, ylabels))
self.stack.addWidget(ArrayEditorWidget(self, data.data, readonly,
xlabels, ylabels))
self.stack.addWidget(ArrayEditorWidget(self, data.mask, readonly,
xlabels, ylabels))
#! -----------------modify start-----------------
# QSpinBox
self.index_spin = QSpinBox(self, keyboardTracking=False)
self.index_spin.valueChanged.connect(self.change_active_widget)
# Labels
self.shape_label = QLabel()
self.slicing_label = QLabel()
# Set the widget to display when launched
self.current_dim_changed(self.last_dim)
#! -----------------modify end-----------------
elif data.ndim == 3:
# We create here the necessary widgets for current_dim_changed to
# work. The rest are created below.
# QSpinBox
self.index_spin = QSpinBox(self, keyboardTracking=False)
--snip--
Hi @DeevenCai thank you for the feedback! Could you give an example code that triggers this error for you? Also, as you already implemented a fix for this, would you like to submit a PR with your proposed changes?
Just in case, if you want to submit your fix our contribution guide could help (https://github.com/spyder-ide/spyder/blob/5.x/CONTRIBUTING.md) using as base branch the 5.x
branch. If you have any doubt let us know!
Thanks for your @dalthviz response. The example code is as follows:
# -*- coding: utf-8 -*-
from netCDF4 import Dataset
ncfile = r'D:\Data\GLASS\GLASS10B02.FVC.1982.nc'
ncid = Dataset(ncfile, 'r')
months = ncid['time'][:] # read time dimension
lon, lat = ncid['lon'][:], ncid['lat'][:] # read longitude and latitude dimension
fvc = ncid['FVC'][:] # read main variable data, which is a 3-Dim NumPy Masked Array, in dim (time, lat, lon)
ncid.close() # close the handle
Then, the variable fvc
is collected by the Variable Explorer Window of Spyder. I clicked fvc
in the Variable explorer window to see what the data looks like, but the Error window was prompted as previously reported. So I checked the source code and modified some of them.
In later use of the Variable Explorer Window to show NumPy Masked Array, more errors occurred. I found that there are many bugs for showing masked array in the variable explorer window (an example given below), therefore, attention should be paid to such issues.
code file: spyder\plugins\variableexplorer\widgets\arrayeditor.py
start line: 889
function: def current_dim_changed(self, index)
error in line 895: string_size = ['%i']*3
correction: string_size = ['%i']*self.data.ndim
I think the dimensions should change with input arrays, not a fixed number 3. Similar errors may occur in lines 866, 874, I am not sure am I right.
As for contributing to Spyder, I can't do anything because I have no experience in software development. I am sorry for this. Thank you guys for your hard work to maintain Spyder.
Thank you @DeevenCai for the new info and the testing you did! Just in case, I was able to reproduce this with this code too:
import numpy as np
x = np.ma.array([[[1]], [[2]], [[3]]])
Thank you @DeevenCai, the 3-D masked array can be double-click-viewed after your modification in file "arrayeditor.py"! However, a side effect is that the 1-D & 2-D masked array CAN'T be viewed with a Spyder error popup . 😂 (And after I remove the modification and restart Spyder, the 1-D & 2-D masked array can be viewed like before.) Hope there to be a final solution to this~
Hi @PlusUltra2021 maybe you could try the solution at https://github.com/spyder-ide/spyder/pull/16919 . Let us know if that covers all the cases (1-D, 2-D, 3-D)
Description
What steps will reproduce the problem?
Error description
Spyder version: 5.1.5 Python 3.8 I want to open a masked 3-D NumPy Array in the variable explorer window, but Spyder prompts an error message, Inner Error. In the previous version of Spyder (e.g., 5.0.5), a masked 3-D array can be opened.
Traceback
Versions
Dependencies