spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.21k stars 1.59k forks source link

override obj val #15071

Open marcchale opened 3 years ago

marcchale commented 3 years ago

Description

What steps will reproduce the problem?

Attempted to use variable explorer to edit an integer within an object from package: pymc3, class: multitrace

Traceback

  File "C:\ProgramData\Anaconda3_\envs\GANS2\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionsdelegate.py", line 273, in <lambda>
    lambda eid=id(editor): self.editor_accepted(eid))
  File "C:\ProgramData\Anaconda3_\envs\GANS2\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionsdelegate.py", line 566, in editor_accepted
    self.set_value(index, conv_func(value))
  File "C:\ProgramData\Anaconda3_\envs\GANS2\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionsdelegate.py", line 442, in set_value
    index.model().set_value(index, value)
  File "C:\ProgramData\Anaconda3_\envs\GANS2\lib\site-packages\spyder\plugins\variableexplorer\widgets\objectexplorer\tree_model.py", line 539, in set_value
    setattr(parent, obj_name, value)
AttributeError: can't set attribute

Versions

Dependencies


# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.6.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.21.0 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
nbconvert >=4.0                :  6.0.7 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
paramiko >=2.4.0               :  2.7.2 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.8.0 (OK)
pygments >=2.0                 :  2.8.0 (OK)
pylint >=1.0                   :  2.7.1 (OK)
pyls >=0.34.0;<1.0.0           :  0.35.1 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  1.0.1 (OK)
qtconsole >=4.6.0              :  5.0.2 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.5.1 (OK)
spyder_kernels >=1.9.4;<1.10.0 :  1.9.4 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  20.0.0 (OK)

# Optional:
cython >=0.21                  :  0.29.22 (OK)
matplotlib >=2.0.0             :  3.3.4 (OK)
numpy >=1.7                    :  1.19.2 (OK)
pandas >=0.13.1                :  1.2.1 (OK)
scipy >=0.17.0                 :  1.6.1 (OK)
sympy >=0.7.3                  :  1.7.1 (OK)

# Spyder plugins:
spyder_notebook                :  0.3.2 (OK)
steff456 commented 3 years ago

Hi @marcchale,

Can you please give me more details of what integer you wanted to change? Remember that if the integer is inside a library we can't modify the package unless you have the package on a development setting.

marcchale commented 3 years ago

@steff456 Greetings and thank you for reaching out. I opened an object of "multi-trace" class from a library called pymc3. https://docs.pymc.io/api/inference.html#pymc3.backends.base.MultiTrace. I was just exploring some results prior to plotting. I tried changing the value for attribute "chain" which is just a label for an array inside the object.

marcchale commented 3 years ago

To clarify, the multitrace object is the output of the library (normal use). I was not editing the library itself. Best Marc

ccordoba12 commented 3 years ago

Please post the code you used to create that object, so we can try to reproduce your problem in our side.

marcchale commented 3 years ago

@ccordoba12 @steff456 I was able to recreate the error by running the following code (adapted from pymc3 documentation) then opening the variable trace from the variable explorer, then clicking on "chains", clicking on "1" and trying to change the value to another number. You may need to install a few libraries (sorry)

"""
Created on Mon Apr  5 14:49:05 2021

@author: mchale
"""
#%% Import things
import sys
import warnings
import os
os.chdir('C:/Users/mchale/OneDrive/AFIT/Research/Mini-Prospectus/GAN Code/gml-cyber/gml-cyber-master')   # Change current working directory
print('WD Updated to', str(os.getcwd()))

# Useful libraries
import pymc3 as pm
import numpy as np
import matplotlib.pyplot as plt
from theano.tensor.nlinalg import matrix_inverse
from ellipse import plot_ellipse
from print_summary import print_summary
import importKDD
import seaborn as sb
sb.set() 
import pickle # python3
import arviz as az
import math
import pandas as pd
from sklearn import preprocessing
import time
import plotly.express as px
import seaborn as sns
from ipywidgets import widgets
from pyDOE2 import *
import warnings

#%% Create Some data in 2D

# True parameter values
alpha, sigma = 1, 1
beta = [1, 2.5]

# Size of dataset
size = 100

# Predictor variable
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2

# Simulate outcome variable
Y = alpha + beta[0] * X1 + beta[1] * X2 + np.random.randn(size) * sigma

#%% Setup Pymc3 model
#%config InlineBackend.figure_format = 'retina'
# Initialize random number generator
RANDOM_SEED = 8927
np.random.seed(RANDOM_SEED)
az.style.use("arviz-darkgrid")

print(f"Running on PyMC3 v{pm.__version__}")

basic_model = pm.Model()

with basic_model:

    # Priors for unknown model parameters
    alpha = pm.Normal("alpha", mu=0, sigma=10)
    beta = pm.Normal("beta", mu=0, sigma=10, shape=2)
    sigma = pm.HalfNormal("sigma", sigma=1)

    # Expected value of outcome
    mu = alpha + beta[0] * X1 + beta[1] * X2

    # Likelihood (sampling distribution) of observations
    Y_obs = pm.Normal("Y_obs", mu=mu, sigma=sigma, observed=Y)

# Fit model with NUTS Sampling
with basic_model:
    # draw 500 posterior samples
    trace = pm.sample(500, return_inferencedata=False)
ccordoba12 commented 3 years ago

Thanks @marcchale for the code.

@dalthviz, please try to reproduce this one because it's related to the Object Explorer.