Fork me on GitHub
#data-science
<
2020-07-09
>
metasoarous18:07:23

@chris441 Is it possible to evaluate a string of python with libpython-clj?

metasoarous18:07:24

What I'm interested in, for the record, is whether I'd be able to make it possible for Oz to execute code blocks of python, as it can with clj code.

David Pham18:07:23

You can probably use the eval built-in python function?

jsa-aerial19:07:59

@metasoarous run-simple-string should do that for you. As an FYI, you will often get faster / better response over on Zulip. That's where Clojure data science folks hang out all the time. For example, there have just been a bunch of changes to TMD.

👍 3
metasoarous19:07:28

LOL; OK... ok...

metasoarous19:07:39

I know you guys keep telling me I need to get over there.

metasoarous19:07:05

I've just been dying from "death by a thousand chat apps"

💯 3
metasoarous19:07:37

@neo2551 @jsa-aerial Thank you both though 🙂

David Pham19:07:26

@jsa-aerial the crazy stuff is the speed at which the changes happened lol. I think the idea of having datasets acting like maps of sequence is cool.

jsa-aerial19:07:44

I'm not so keen on having datasets acting like seqs of maps. As I stated in one of the threads, this is very misleading because they are absolutely nothing like seqs of maps. This 'clojury' kind of interface is handy in someways (for novices) but if you are more a R data.table/dplyr sort (or pandas for that matter) it is confusing. I am moving to just using tablecloth so I don't need to look at this stuff! 😁

❤️ 3
metasoarous19:07:50

I'm a big fan of seq of maps approach; I realize it's in conflict with pandas, but it's actually the thing I don't like about pandas, so it's fine with me 🙂 Somehow, the approach in R seems more reasonable given that it's an array/vector oriented language; Somehow, the decisions come together in a more comprehensive way to me. In python, it feels in conflict with traditional pythonic programming practices, and that conflict has always bugged me.

💯 3
3
metasoarous19:07:57

But to each their own 🙂

metasoarous19:07:46

So using run-simple-string you can only get back a 1 or 0. Any way to get a reference to the last evaluated form?

jsa-aerial20:07:24

That's an issue with PyRun_String; it is statement oriented... But run-simple-string passes back a map of globals, locals and result. But since PyRun_String is not expression oriented, you won't get back the value of a function call. Probably going to need to set a variable and then interrogate that

aaelony18:07:17

why not just shell out to python if you have straightup python code?

metasoarous18:07:26

Well, ideally it would be possible to share the same process/environment

metasoarous18:07:57

It's ok though; I think I can work around it.

metal 3
metasoarous18:07:15

Thanks for considering/asking @U0CDMAKD0!

jsa-aerial20:07:09

The big reason to use libpython-clj and not just shell out to python, is that you can then interactively work with python from clj/cljs. This is seriously cool and can be extremely useful - when you can get python to actually work...

✔️ 3
metasoarous19:07:05

I can imagine definging variables in the python code that you might be able to retrieve data from clojure side, but that limits what I was hoping to do somewhat

jsa-aerial19:07:56

I think Chris in an much early thread about this (what should the interface look like) had a great point. Which was that TMD was adding an important and orthogonal capability to Clojure. As I stated in one of the recent threads, we don't want to start sliding into 'ORM land', which is very similar to this situation: "why not have RDB databases look and act like objects - if you squint enough, they sort of do, and developers will be happier" (until they aren't).

jsa-aerial20:07:24

That's an issue with PyRun_String; it is statement oriented... But run-simple-string passes back a map of globals, locals and result. But since PyRun_String is not expression oriented, you won't get back the value of a function call. Probably going to need to set a variable and then interrogate that

jsa-aerial20:07:33

Yeah, it sucks - but that's Python for you! ¯\(ツ)

metasoarous20:07:33

Phooey! Thanks for explaining though. I guess for what I want I'll need to have a function you call from python when you want to render/view something.

jsa-aerial20:07:56

The way I've been approaching this (R is vastly better at doing it) is to just calculate data on the py side of things and have the result come back to clj/cljs (typically as TMD DS). Then you do any final expl and massaging (say to put it into VGL/VG data shape) in clj/cljs. Not sure if that fits in with what you are doing though