Skip to content

dataframe: refuse an Array block result of map/apply before converting it - #17

Open
tannevaled wants to merge 3 commits into
mainfrom
fix/map-array-result
Open

tannevaled wants to merge 3 commits into
mainfrom
fix/map-array-result

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Series#map and DataFrame#apply converted every block result with dfValue before go-dataframe refused a nested one. s.map { b } over 200k rows therefore built 200k converted Arrays first.

go-dataframe's fromValues (used by Series.Map and DataFrame.Apply, dataframe v0.1.0 build.go:146) refuses a []any ("cannot hold []interface {}"), and no other path accepts nested results, so the Array is now refused up front with an ArgumentError naming the row.

Measured, 200k rows, b = 64-element Array (same machine, GC before each):

time alloc mallocs
map { b } before 1.27 s 465 MiB 1.80M
map { b } after 4 ms 6 MiB 0.20M
map { |x| x * 2 } v0.4.0 0.35 s 16 MiB 1,198,201
map { |x| x * 2 } f094d13 (#14) 0.14 s 16 MiB 1,198,202
map { |x| x * 2 } after 0.12 s 16 MiB 1,198,202

Refs #14. A flat block costs the same before and after it (one malloc apart). The cyclic/deep cases of s.map/df.apply that dfValue used to refuse are now refused as an Array result; their tests moved to a dedicated test that also asserts the allocation bound under GOMEMLIMIT.

🤖 Generated with Claude Code

tannevaled and others added 3 commits November 30, 2026 21:01
…ly before converting it

A column holds scalars: go-dataframe's fromValues refuses a []any ("cannot
hold []interface {}") on the Map and Apply paths, and no other path accepts
nested results. Yet the block result went through dfValue first, so
`s.map { b }` over 200k rows built 200k converted Arrays (4.7 s, 5.9 GiB,
88M allocs on a large b) before the refusal.

blockResult refuses a []any at once with an ArgumentError naming the row.
200k rows x 64-element Array: 465 MiB / 1.80M allocs -> 6 MiB / 0.2M allocs.
A flat block costs the same as before (1.198M allocs at v0.4.0 and at
f094d13: #14's memo adds no allocation to scalar results).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
An Array was refused, but a Hash (or any other object) result still went
through Go() and dfValue before go-dataframe refused it: `big.map { h }` over
20k rows with a 1000-key Hash cost 1.8 GiB. blockResult now takes the Ruby
value and accepts exactly the classes that become what fromValues takes
(nil, true/false, Integer, Float, Complex, String, Symbol, Time), refusing any
other by class name at its row, before any conversion.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant