clerk

zane 2023-09-24T17:43:30.447459Z

Getting this error pretty often when working with Clerk + TableCloth:

Unhandled java.lang.NullPointerException
Cannot invoke "java.util.Map$Entry.getValue()" because "<local6>" is null
Curious whether anyone else has seen it before?

mkvlr 2023-09-24T17:50:32.906459Z

I haven’t but not using TableCloth heavily. Can you share your tablecloth viewer? In previous implementations I’ve seen all Clerk did was convert it to a seq of seqs so not much going on.

zane 2023-09-24T18:00:59.817079Z

I’m converting it to maps using tc/rows and then passing it to either clerk/table or clerk/vl.

mkvlr 2023-09-24T18:14:38.197659Z

so something along these lines?

(ns tablecloth-viewer
  (:require [tablecloth.api :as tc]
            [nextjournal.clerk :as clerk]))

(comment
  (clojure.repl.deps/add-lib 'scicloj/tablecloth {:mvn/version "4.04"}))

(def tablecloth-table-viewer
  {:pred tc/dataset?
   :transform-fn (clerk/update-val (fn [dataset]
                                     (clerk/table {:head (into [] (tc/column-names  dataset))
                                                   :rows (into [] (tc/rows dataset))})))})

(clerk/add-viewers! [tablecloth-table-viewer])

(def dataset
  (tc/dataset "" {:key-fn keyword}))

zane 2023-09-24T18:14:59.105899Z

I’m not using a custom viewer at all.

mkvlr 2023-09-24T18:18:10.041399Z

so having the conversion happen inline? Are you using tc/rows :as-maps ?

zane 2023-09-24T18:18:17.720609Z

Yes, and yes.

mkvlr 2023-09-24T18:18:57.015429Z

I’d recommend using seqs of seqs as in my example as there’s no normalization work for clerk to do and the order of the cols is kept

zane 2023-09-24T18:19:23.147689Z

Well, among other things I need to pass it to Vega-Lite which expects objects.

mkvlr 2023-09-24T18:19:26.797759Z

unsure if that fixes your original issue however

mkvlr 2023-09-24T18:20:39.769409Z

can you share the stacktrace for your issue?

zane 2023-09-24T18:22:23.700679Z

Yes, sure. Next time it happens.

👍 1
zane 2023-09-24T18:22:29.708799Z

(It appears to be intermittent.)

mkvlr 2023-09-24T18:23:46.186689Z

if nextjournal.clerk.viewer/normalize-table-data shows up in the stacktrace what I wrote above might be worth a try

zane 2023-09-24T18:24:54.045309Z

zane 2023-09-24T18:25:01.028669Z

There’s part of the stacktrace.

zane 2023-09-24T18:25:06.260529Z

It’s showing up in the browser.

mkvlr 2023-09-24T18:26:18.222809Z

huh, interesting, seems to be related to the editscript diff

mkvlr 2023-09-24T18:27:51.874159Z

unfortunately I don’t know anything about to underlying ham-fisted.ImmutList datascructure to know what’s going on

mkvlr 2023-09-24T18:27:59.438039Z

is there a channel for tech-ml-dataset?

zane 2023-09-24T18:35:36.387139Z

I don’t think so.

zane 2023-09-24T18:35:40.656609Z

Probably #data-science is best?

👍 1
zane 2023-09-24T18:35:43.600739Z

Longer stack trace:

zane 2023-09-24T18:35:51.573559Z

Daniel Slutsky 2023-09-25T20:40:00.249899Z

Hi. I'm not sure whether this is related, but in the past, some tech.ml.dataset/Clerk incompatibilities were caused by tech.ml.dataset's overriding of https://github.com/taoensso/nippy serializations (which were used in Clerk's cache). We recorded one such behaviour https://github.com/scicloj/visual-tools-experiments/tree/main/clerk-cache-tmd-columns-tc-1 (but I think it has been fixed later). I'm mentioning it here since this kind of situation might be difficult to debug without knowing of such relationship (and is tricky to reproduce because it may depend on the cache state).

👀 1
mkvlr 2023-09-26T06:21:46.814509Z

thanks @daslu. The stacktrace makes me believe it’s unrelated to Clerk’s caching however as it happens when Clerk is doing a editscript diff to figure out the diff to send to the browser to update the display.

👍 1
zane 2023-09-24T18:02:13.074609Z

Here’s another weird (to me) one:

1. Caused by java.lang.IllegalArgumentException
   No implementation of method: :peek-char of protocol:
   #'clojure.tools.reader.reader-types/Reader found for class:
   rewrite_clj.reader.NewlineNormalizingReader

zane 2023-09-24T18:02:25.491799Z

The file evaluates just fine in the REPL.

zane 2023-09-24T18:02:39.904439Z

Might this be an issue with tagged literals, which we use?

mkvlr 2023-09-24T18:15:08.815009Z

can you share a repro for this one?

zane 2023-09-24T18:15:34.854939Z

That would be challenging, but I can try.

mkvlr 2023-09-24T18:21:37.935509Z

do you have code of the failing cell?

mkvlr 2023-09-24T18:29:26.265919Z

ah wait, so this is code with a custom reader?

mkvlr 2023-09-24T18:30:08.797209Z

clerk uses edamame to read, but it should respect *data-readers*

zane 2023-09-24T18:30:19.798939Z

The code doesn’t use custom readers.

zane 2023-09-24T18:30:26.875059Z

But the code reads an EDN file that uses tagged literals.

mkvlr 2023-09-25T12:21:16.959869Z

Can’t really say what goes wrong here. Would be great to have a repro.