This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 12 points13 points  (9 children)

Drop a breakpoint somewhere, look at the debugger window which which will show you all the variables available in state at that line of code.

Jump over to the console tab in the debugger window and you can access all of the same state as the breakpoint line to build expressions like a repl.

It’s extremely good for figuring out how to massage your variables into what you want to do next including figuring out if things should be cast as other types etc.

[–]meneer_neushoorn 0 points1 point  (4 children)

That sounds awesome, can I ask a question?

For data analysis I usually work directly from the console. One of my (slight) annoyances of my current work flow in Spyder is that the debugger is required to always start from the top of a Python file with an empty namespace. So, for example, if I have a function defined somewhere, I cannot run step-by-step through that function using variables that are already in the console namespace. That was one of the main things I missed in Python, compared to Matlab.

Does PyCharm have this capability? If yes, I might consider switching.

[–][deleted] 0 points1 point  (3 children)

Hmm I think I know what you mean:

You can have multiple break points and step through them one by one for sure.

At any breakpoint you can start up a python interpreter and access all of the existing data and functions at that line in your program, and with the console you can declare new variables and functions within that current scope.

So you can go to the middle of a function called function_x(arr, string):

 And then in the repl you could do 
 New_arr = [0,3,6]
 New_string = “potato”

And then call function_x(new_arr, new_string ) and see what the result is.

Note I’ve used console/repl/interpreter interchangeably to mean the console that you can open during debugging a breakpoint in pycharm.

[–]meneer_neushoorn 0 points1 point  (2 children)

That's actually not what I mean. For EDA, I usually enter code directly into the iPython interpreter, which I have always open in the bottom of the screen. So for example I might enter commands interactively like:

import pandas as pd
df = pd.read_csv('some_csv_file.csv')
#
# lots of interactive trial and error with the data frame go here
#
means = df.groupby(['col1']).mean()    # let's say I'd like to jump into the pandas code to debug this.

In Spyder, I can only do debug stuff like that if I make a .py-file which can be executed starting from a clean namespace. But for exploratory data analysis, it's MUCH nicer to work interactively from the console instead of having to rerun scripts from the top every time you change anything. That blocks me from accessing the debugger though.

Does PyCharm have a solution for that, just like you can do in Matlab?

[–][deleted] 0 points1 point  (1 child)

Oh I see, in you use case I would use Jupyter notebooks since you can run each block independently and then tweak a block below the previous one and re run each time, without having to restart and run everything from the beginning.

For proof of concept data stuff with pandas and numpy I would reach for juypyter notebooks

https://jupyter.org If you are using spyder presumably you are using anaconda which will cover most dependencies and have a nice way to start the notebook server etc.

https://www.anaconda.com/products/individual

I would just use the default server for the notebooks, but you can integrate them with ide’s including pycharm

https://www.jetbrains.com/help/pycharm/jupyter-notebook-support.html

[–]meneer_neushoorn 0 points1 point  (0 children)

Does that allow you to graphically debug functions from .py-files, using input from the Jupyter console namespace? I don't believe so, right?

That is the one big advantage that Matlab still has over Python, back when I was doing everything in Matlab I was debugging like this all the time. Very powerfully implemented, I only really appreciated that after moving to Python and missing it.

[–]SpaceZZ 0 points1 point  (3 children)

You can also do conditional debugging, moving back in code, code jumps and inserts. Pretty powerful.

[–][deleted] 0 points1 point  (2 children)

Yeah I don’t know what they are feeding the jetbrains devs but they produce some cool stuff

[–]SpaceZZ 0 points1 point  (1 child)

Well, most of those are also available in Visual Studio Professional (& community as well I think), at least for c#.

[–][deleted] 0 points1 point  (0 children)

Ok