These are chat archives for spyder-ide/public

24th
Nov 2018
Venkatachalam
@venkatesh_km1_twitter
Nov 24 2018 08:18
how to get or see Object Inspector in Spyder
I am not able to get it through Help
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 08:18
The "Object Inspector" was renamed the Help pane in Spyder many years and versions ago.
Venkatachalam
@venkatesh_km1_twitter
Nov 24 2018 08:19
@CAM-Gerlach In Help how I can get to know the syntax of Imputer?
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 08:19
The default shortcut to get help on an object with an appropriate docstring is Ctrl-I, IIRC.
Venkatachalam
@venkatesh_km1_twitter
Nov 24 2018 08:20
@CAM-Gerlach after pressing Ctrl-I, I see "No documentation available"
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 08:23
Try it again, I got it work work on my machine testing it now with my cursor indicated by |.
import sklearn.preprocessing.imputation
sklearn.preprocessing.imputation.Imp|uter
Does it work on other objects, just not that one? Does it work in the Console? Does it work if you restart Spyder and try it again?
image.png
Venkatachalam
@venkatesh_km1_twitter
Nov 24 2018 08:41
Thanks, will try now
@CAM-Gerlach Thanks will try now
Venkatachalam
@venkatesh_km1_twitter
Nov 24 2018 08:55
@venkatesh_km1_twitter Got it. Thanks
nihalojha
@nihal_ojha_twitter
Nov 24 2018 14:23
hello
I have downloaded the anaconda version 5.3 but I am unable to open anaconda naviagator, please help
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 16:51

Hi guys,

I'd like some help in get a debugger working for pytest. I am using Hypothesis and I'd love being able to see the dataframes I'm generating. Someone has a hint? Thanks

CAM Gerlach
@CAM-Gerlach
Nov 24 2018 17:20
@nihal_ojha_twitter This is the Gitter for the Spyder IDE, not Anaconda; you're better off getting support through an Anaconda-related channel instead for that problem.
You can launch Spyder through a standard start menu shortcut (on Windows), or from the command line with spyder from an Anaconda prompt (Win), Terminal (macOS) or the command line (Linux), the latter two you might have to do source activate base first.
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 17:28
@nicoabie I'm not an expert on that, but you could try just running the tests as a script in Spyder and inserting breakpoints where appropriate. Then, you can just use the Variable Explorer as normal to view the dataframe. You can also insert a print(df) command and then stop the test function after the relevant code has executed withraise Exception(), and when you run it with Pytest (you might need-v``) it will include your output in the test report. Finally, we are currently implementing a brand-new, full-featured debugging kernel for Spyder 4, and you can also check out our Spyder-Unittest plugin by @jitseniesen which allows you to configure, run and view the results of your tests from a GUI right inside Spyder.
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 17:35
@CAM-Gerlach many thanks for the fast response.
I tried running them as a script but the debugger does not kick in as for normal python code. I've checked out and used the Spyder-Unittest which I think is great but it doesn't allow me to debug the code either. I can debug the code with visual studio code it has no such a good dataframe viewer as Spyder. If help is needed in order to move this forward I'm here :)
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 17:39

I tried running them as a script but the debugger does not kick in as for normal python code.

Just to confirm, you ran them via the Debug menu option, with your breakpoints set to the appropriate places (it will only stop on executable lines, not continuations)?

Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 17:40
let me take a screenshot
image.png
if I place the breakpoints at the import statements it stops
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 17:44
Yeah, that should be fine. My guess is has something to do with ipdb's limitations combined with whatever particular stuff pytest is doing.
@ccordoba12 Will the new debugging kernel @dalthviz is writing for Spyder 4 Beta 3, due out around the end of December, be able to handle this?
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 17:46
What I understand is that ipdb is not aware of that is a pytest file instead of just a regular python file so it is invoking it as python file.py instead of python -m pytest file.py
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 17:46
Oh, I thought your tests were actually running properly but ipdb was not kicking in. Is that not the case?
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 17:46
so I was wondering it it was a way of telling ipdb that
the tests do not run when debugging, they run if I use the Spyder-Unittest plugin
when debugging It just passes through the file
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 18:40

@nicoabie After some mostly unrelated finagling, placing a breakpoint and starting debugging at it works fine for me (at least in Spyder 4, but it should still work the same in the latest Spyder 3), on Spyder's own test suite (in this example, the test file spyder/utils/tests/test_sourcecode.py). I set the breakpoint, put

if __name__ == '__main__':
        pytest.main(["--capture=sys", "spyder/utils/tests/test_sourcecode.py"])

at the end of a test file (it can be your test file of interest, another one, or any other script, so long as you've set your working directory correctly with Spyder), and triggered debugging, and it worked just fine; I was able to step through, print variables in the console, and see and interact with them in the Variable Explorer, as well as run all the tests of course and see the output with or without debugging.

image.png
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 18:50
@CAM-Gerlach it seems I don't have the test_sourcecode.py on that path but this is looking very promising. I'm using spyder 3.3.1
I'll take a look to see if I can find it. I installed spyder through conda, I hope that does not make a difference in that regard
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 18:50
You could also run your test file by any normal means in Spyder and set breakpoints via import pdb; pdb.set_trace() or the new breakpoint() builtin in Py 3.7 and Spyder's debugger will automatically trigger.

it seems I don't have the test_sourcecode.py on that path but this is looking very promising.

That's just one of Spyder own test files, for the purposes of the example. You'd want to replace that with whatever test file of your own that you're trying to run.

Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 18:53
Yeah but the key here is telling the debugger that pytest is the real thing to run and not just the file because it has no entry point (I have two weeks of python, sorry if I say something that makes no sense at all and thanks a lot for the feedback)
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 18:54

Yeah but the key here is telling the debugger that pytest is the real thing to run and not just the file because it has no entry point

That's why I mentioned to add

if __name__ == '__main__':
        pytest.main(["--capture=sys", "path/to/your/test_file.py"])
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 18:56
yeah exactly what I was not being able to do without your help. Now I got it, let me come back to you in a few moments with the result. thanks again and the "finagling" was very funny, I had to look it up hahahaha
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 18:57
To whatever file. You'd normally want to do that for any pytest file (or at least just pytest.main()) since pytest.main() is how you run a file with Pytest from Python itself rather than calling pytest path/to/test_file.py from the command line. That's not specific to Spyder—that's a pytest thing. Check out the pytest docs for more.
If it worked in another IDE, it was likely either a happy accident or they have specific workarounds implemented to avoid having to do this, as one has to do generally.
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 19:00
Got it, I'm very new to python so all of this needs a little bit of time to process but I'm catching up
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 19:02
You're already very knowledgeable for two weeks experience! What language(s) are you coming from?
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 19:04
the ones you see at the uni + c#, js, ts, scheme (just for fun)
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 19:09
@CAM-Gerlach It's working, can't believe it! I created a tests.py with the magic lines calling pytest with a reference to my test file and the on my test_file imported pdb and used pdb.set_trace() as you said and it's working like a charm. I can see now the dataframes Hypothesis is generating!!! Can't thank you enough!
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 19:30
@nicoabie Oh my, you're quite the polyglot! You're probably well beyond me already in general programming acumen; I'm just an atmospheric scientist after all. Although, funny enough we're running a big field campaign down in Argentina with a bunch of different universities to determine once and for all which country's storms are bigger measure and characterize severe convention during the warm season.
Sure! Glad to hear! You should be able to also set breakpoints in the GUI, with whatever the default shortcut is or double-clicking to the left of the line number. You can also set conditional breakpoints, which will only trigger if arbitrary conditions you set are met—particularly useful for loops or helper functions.
Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 19:36
@CAM-Gerlach to be an atmospheric scientist you are very good at hacking some code!
I don't know I'm that good with probabilities and statistics as I'd like to but I'm trying to learn them again for ML
The GUI breakpoints didn't seem to work but I'm perfect with the pdb.set_trace() for now, even though it is true that I cannot set them conditionally unless well I wrap them with an if hahaha
CAM Gerlach
@CAM-Gerlach
Nov 24 2018 19:43

The GUI breakpoints didn't seem to work

They only work if you run it via Debug > Debug and not the Run menu options; that's by design.

CAM Gerlach
@CAM-Gerlach
Nov 24 2018 19:51

to be an atmospheric scientist you are very good at hacking some code!

Eh, just good at Googleing, reading the documentation and trial and error, not to mention making myself sound smarter than I actually am.

I don't know I'm that good with probabilities and statistics

That's pretty important for ML :) There are some decent books on that subject specifically for ML, I've heard.

Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 19:51
Of couse, I was pressing the Start Debugging button (the one in blue that has a play symbol followed by a pipe symbol) but I believe it is because of the Hypothesis framework that add some decorators to the functions. Anyway, pdb.set_trace() is my new best friend. Have you used it https://hypothesis.readthedocs.io/en/latest/? it is great

Eh, just good at Googleing, reading the documentation and trial and error, not to mention making myself sound smarter than I actually am.

That's the trick haha

CAM Gerlach
@CAM-Gerlach
Nov 24 2018 19:56

I believe it is because of the Hypothesis framework that add some decorators to the functions

That could be it—not sure.

Have you used it

I've heard of it, but never actually got my hands dirty with it yet. Sounds very interesting and powerful though!

Nicolás Andrés Gallinal
@nicoabie
Nov 24 2018 19:59
I strongly recommend it, if you need to create many use cases and test some invariant it is ideal! I've used jsverify before, both come from haskell's quickcheck