KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums PyKX pykx is returning different output compared to embedQ

Tagged: ,

  • pykx is returning different output compared to embedQ

    Posted by user931206 on July 11, 2024 at 10:35 am

    I have recently switched from embedPyb to PyKX.
    I had a function called decodeBuffer which was outputing colls like in image1

    But now after the transition it outputs col where all string values are symbols.

    The only thing that changed was the addition of this function:

    .util.convertBytesToString:.pykx.eval[“lambda x: x.tobytes().decode(‘UTF-8’)”];

    I am not sure if the above change is what is causing this or a change in the way pyKx is output data, but it is the only thing that change. image2 shows the code changed from before pykx to after pykx

    decodeFlatBuffer now outputs what you can see in Image3.

    I could cast them all to string, but some of the columns are much more complex than what you can see in the image

    rocuinneagain replied 5 months, 2 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • rocuinneagain

    Member
    July 11, 2024 at 1:26 pm

    See: Upgrading from embedPy – PyKX

    PyKX converts Python strings to q symbols which differs from embedPy

    q).pykx.eval["'hello'"]`
    `hello

    Pass your data back as Bytes for it to become q character vectors

    q)string_to_bytes:.pykx.eval["lambda x: bytes(x, 'utf-8')"]
    q)string_to_bytes[.pykx.eval["'hello'"]]`
    "hello"

  • rocuinneagain

    Member
    July 11, 2024 at 1:48 pm

    PyKX also will convert a hsym directly to a Path type object

    q).pykx.print[.pykx.eval["lambda x:x"]`:/path/to/file]
    /path/to/file
    q).pykx.print[.pykx.eval["lambda x:type(x)"]`:/path/to/file]
    <class 'pathlib.PosixPath'>

    If you want a string of the Path you can call:

    streamer:.pylibs.security[`:smStreamer] .pykx.eval["lambda x:str(x)"] file

Log in to reply.