This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-25
Channels
- # announcements (4)
- # babashka (58)
- # beginners (21)
- # calva (42)
- # clj-kondo (15)
- # cljdoc (16)
- # cljs-dev (11)
- # clojure (57)
- # clojure-denmark (1)
- # clojure-europe (24)
- # clojure-france (4)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-spec (6)
- # clojure-uk (2)
- # clojurescript (19)
- # clr (4)
- # conjure (1)
- # core-logic (3)
- # cursive (5)
- # data-science (2)
- # datascript (6)
- # datomic (3)
- # emacs (4)
- # events (3)
- # fulcro (17)
- # gratitude (2)
- # hyperfiddle (4)
- # introduce-yourself (3)
- # jobs-discuss (2)
- # lsp (27)
- # malli (22)
- # pathom (73)
- # portal (21)
- # re-frame (5)
- # releases (1)
- # vim (8)
- # xtdb (28)
Are there any obvious reasons why I might not be able to tap a Pandas DF into Portal? I'm dipping into libpython-clj and it seems to not play very nicely.
As far as I know all libpython-clj objects have Java wrappers on them.
Nothing, and in fact it seems to break my portal instance, bc if I try to tap trivial clojure values thereafter, it also does nothing
ok, I'll think on it/explore some more. That seems reasonable to me because I do believe that libpython-clj forwards any of java.lang.Object
's .toString
calls to __str__
in Python
I don't know if that would be problematic under these circumstances.
(ns portal.runtime.jvm.server)
(defn- rpc-handler-local [request]
(let [session (rt/open-session (:session request))
send! (fn send! [ch message]
(server/send! ch (rt/write message session)))]
(server/as-channel
request
{:on-receive
(fn [ch message]
(let [body (rt/read message session)
id (:portal.rpc/id body)
op (get ops (:op body) not-found)]
(binding [rt/*session* session]
(op body (fn [response]
(try
(send!
ch
(assoc response
:portal.rpc/id id
:op :portal.rpc/response))
(catch Exception ex
(send!
ch
(assoc response
:return (Throwable->map ex)
:portal.rpc/id id
:op :portal.rpc/response)))))))))
:on-open
(fn [ch]
(swap! c/connections assoc (:session-id session) (partial send! ch))
(when-let [f (get-in session [:options :on-load])]
(f)))
:on-close
(fn [_ch _status]
(swap! c/connections dissoc (:session-id session)))})))
might help debug this issue for youI get TypeError: unhashable type: 'dict'
when I try libpython-clj locally, I think this is probably why you are having issues. Not sure what the fix is here :thinking_face:
This makes sense since portal will keep track of all objects it sends to the client in a hash map
Sorry been away from my computer. So if I understand right, you mean that Portal can't work with Python dicts at all or is this some idiosyncracy of Pandas?
I don't know the libpython-clj API well yet as this is my first day using it but they have a set of factory functions for converting between Java and Python objects that I will look into
Though I wonder whether doing so would be at the expense of Pandas' representations
I think all python objects will probably cause issues. I wonder why they don't proxy hashing :thinking_face:
Ohh, https://github.com/clj-python/libpython-clj/blob/e6ec1aca703fdf736ea971be22f0624190fac381/src/libpython_clj2/python/bridge_as_jvm.clj#L230-L231 the issue is python can't hash dicts:
>>> hash({})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
Yeah its been quite some time since I was last a Python user but that particular error is fresh in my mind
IIRC Pandas also has various ways to reshape DFs into more generally friendly shapes anyway
So I will explore those as this isn't a huge priority for me. But it would be super cool to get DFs into Portal one day!
I'll see about reducing the constraints on objects in the portal cache :thinking_face:
I got https://github.com/djblue/portal/commit/6f63556688ce2ff97bc5e7cc15aa66ecd472e8ff working, but not sure if I'm a fan especially because portal doesn't know what to do with the value {'a': 'b'}