1.5.1 Series to Racket values🔗ℹ

series->list is Series.to_list(), and series->vector its vector twin. The column is copied out in one foreign call into a buffer Racket owns, not one call per element; that buffer is the conversion’s only memory beyond its result. A null comes out as polars-null, or as the #:null value.

> (define df
    (dataframe (list (series '(1 2 3) #:name "foo")
                     (series '("ham" "spam" "jam") #:name "bar"))))
> (~> df (ref "foo") series->list)

'(1 2 3)

> (~> df (ref "bar") series->vector)

'#("ham" "spam" "jam")

> (define gappy (series (list 1 polars-null 3) #:name "value"))
> (series->list gappy)

'(1 polars-null 3)

> (series->list gappy #:null 0)

'(1 0 3)

Every element is what ref returns: exact integers, flonums, booleans, strings, and gregor values for the temporal dtypes.

> (define people
    (~> (dataframe
         (list (series '("Alice Archer" "Ben Brown") #:name "name")
               (series (list (datetime 1997 1 10 8 30 0) (datetime 1985 2 15 17 0 0))
                       #:name "birthdate")
               (series '(57.9 72.5) #:name "weight")
               (series '(#t #f) #:name "parent")))
        (with-columns (alias (cast "birthdate" 'date) "birthday")
                      (alias (cast "birthdate" 'time) "clock"))))
> (for/list ([name (column-names people)])
    (~> people (ref name) series->list))

'(("Alice Archer" "Ben Brown")

  (#<datetime 1997-01-10T08:30:00> #<datetime 1985-02-15T17:00:00>)

  (57.9 72.5)

  (#t #f)

  (#<date 1997-01-10> #<date 1985-02-15>)

  (#<time 08:30:00> #<time 17:00:00>))

API gaps: datetimes come out floored to the whole second, where to_list keeps microseconds; a 'binary column has no Racket value.