namo.rb 0.32.8 → 0.32.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4889db6dce5c63a9cc355e5b68611a33cb1dacbe94f678a6b11cd0a5c5c3fb0c
4
- data.tar.gz: 561246d0002efb96b1235fbf7d64b20e4816217a78757477a2784a016e5a94c2
3
+ metadata.gz: 102a39ba577957cdb56d734c56e89093be6564c1e0e5a4f51ec1fcdda9d281a3
4
+ data.tar.gz: bc01e5043bd56cc9e178074332b36524b400cef4ad4f3cb35f2e6b88a50a68d2
5
5
  SHA512:
6
- metadata.gz: 130de24b9419ccb107195ae5205dda09c5f46fd996dba9f38ea976a19619e9718cbb1d812810cf737571b955f1438e4651bfd6a39d5d5c8cf4a709b62cfb4596
7
- data.tar.gz: c4c90a3798c7caf69e19c069979f423648c64fa8d53dd9122da8187d5d7e2db3f70d2e463d5b922ea61fe6d4fe53fc16cdc0cf1d98138a905f7603baf08a294f
6
+ metadata.gz: 3e2c6203b00c8e4799f45702e1776d51415399b68587e73c43aa539bff007ef054c1a69c0d23abd78f63acfd9433d99811b470ff9dc16583b0359608da889e9c
7
+ data.tar.gz: e10bcedae84d2a301a8f9188a5694f2f44202b6e8b787380fa698251ff8222b612265d741359596f98a823a3a172e20f7ca679119b7fb7783781cc0c6af8e25e
data/CHANGELOG CHANGED
@@ -1,7 +1,23 @@
1
1
  # namo/CHANGELOG
2
2
 
3
+ ## 20261103
4
+
5
+ 0.32.10: ~ Namo#materialising: A frozen Namo can be read again, and two threads reading one Namo no longer share a scope.
6
+
7
+ 1. ~ Namo#materialising, #values_for: + #materialised_scopes, - @materialised. An access's scope is held per fiber, keyed by the Namo, rather than on the Namo itself. Since 0.29.0, every read wrote to the Namo, so values, coordinates, and to_a raised FrozenError on a frozen Namo, and two threads reading one Namo shared a scope which either could clear while the other was using it.
8
+ 2. ~ test/namo_test.rb: Reading a frozen Namo through a two-arity formula is tested, as is an access keeping its scope when another thread's access to the same Namo ends part-way through it.
9
+ 3. ~ ROADMAP.md: The 0.32.10 change is described.
10
+ 4. ~ Namo::VERSION: /0.32.9/0.32.10/
11
+
3
12
  ## 20261102
4
13
 
14
+ 0.32.9: + comparison/setup: Builds the environments the comparison/*_claims scripts run in, at the versions COMPARISON.md names, or with --latest the newest releases.
15
+
16
+ 1. + comparison/setup: Builds .venv/ with uv, and in .tools/ R and its packages with micromamba from conda-forge and Julia from its tarball, checked against the sha256 julialang.org publishes, with its packages; then removes the downloads and package caches. Pins pyarrow besides the packages COMPARISON.md names, since pandas stores strings with it where it is installed, which shows in what pandas_claims.py prints.
17
+ 2. ~ comparison/README.md: The setup instructions are comparison/setup, and each script runs with what it builds, where they had been the uv commands for Python and "given an environment" for R and Julia.
18
+ 3. ~ CHANGELOG: The 0.21.0 and 0.22.0 summaries end at their commit subjects, the rest moved into their numbered items; the 0.23.0 summary /body/collection/, as its commit subject has it.
19
+ 4. ~ Namo::VERSION: /0.32.8/0.32.9/
20
+
5
21
  0.32.8: ~ Namo::Row#match?: A Range selects by cover?, so beginless and endless ranges of Dates and Strings select rather than raising TypeError.
6
22
 
7
23
  1. ~ Namo::Row#match?: A Range is tested with cover? and an Array with include?, where both had been tested with include?, which raises for a beginless or endless range of anything not numeric. A bounded range of Strings now selects by ordering, as a bounded range of numbers already did, rather than by membership of its succ sequence.
@@ -306,7 +322,7 @@ A base Namo's constituents are formularies and rows: << dispatches a Module to a
306
322
 
307
323
  ## 20260627
308
324
 
309
- 0.23.0: + Namo::Formulary — A formulary is a reusable body of derived dimensions a Namo instance may draw upon.
325
+ 0.23.0: + Namo::Formulary — A formulary is a reusable collection of derived dimensions a Namo instance may draw upon.
310
326
 
311
327
  1. + lib/Namo/Formulary.rb: + Namo::Formulary, an empty marker module. A module includes it to brand itself a formulary; attach raises ArgumentError for an untagged module, so an ordinary module of helpers can't be mistaken for a body of derivations.
312
328
  2. ~ lib/Namo/Formulae.rb: + attach(modul), aliased as << — after the marker guard, extends a single memoised inert host (@host ||= Object.new) with the module and stores each of its public_instance_methods(false) as a Method bound to that host, then returns self. One host per Formulae across all attaches, so the bound Methods share a self-free receiver and a formulary method can't shadow Namo's API. No other change: derive, key?, required_parameter_count, keys, merge/dup/reject, and ==/eql?/hash are the 0.22.0 store-only methods, and they handle the formulary methods because the formulary methods are now store entries.
@@ -318,19 +334,19 @@ A base Namo's constituents are formularies and rows: << dispatches a Module to a
318
334
 
319
335
  ## 20260626
320
336
 
321
- 0.22.0: + Formulae#derive — move formula invocation out of Row#[] and into Formulae. [] keeps its meaning (the stored callable, as at 0.21.0); the new derive(name, row, namo, *arguments) resolves a named formula to its value. derive over call: the receiver is the collection, not the callable, so the verb says the collection derives a value via the named rule rather than borrowing Proc#call's "invoke the receiver"; and the result is whatever the proc returns, not necessarily numeric, which a neutral verb leaves open. Indexing a Formulae is storage access, not a Namo operation, so [] returning the callable carries no inconsistency with the dimension-value [] of Namo and Row — different domains, same spelling. Behaviour-preserving at the usage level: row[:revenue], namo[:x] = formula, values, and selections are unchanged.
337
+ 0.22.0: + Formulae#derive — move formula invocation out of Row#[] and into Formulae.
322
338
 
323
- 1. ~ lib/Namo/Formulae.rb: + derive(name, row, namo, *arguments), the formula resolver — invocation mechanics lifted whole from Row's formula branch (collection-scoped formulae are called (row, namo, *arguments), row-only formulae (row)). + required_parameter_count(name), public, a property of the stored callable. collection_scoped? and raise_unless_namo_context move in as private; the latter takes namo as a parameter rather than closing over Row's @namo. [] and []= are untouched — [] still returns the stored callable.
324
- 2. ~ lib/Namo/Row.rb: #[] delegates formula resolution to @formulae.derive(name, self, @namo, *arguments); Row keeps only the fail-fast argument guard, the formula-vs-data dispatch (@formulae.key?), and the data fallback (@row[name]). collection_scoped?, required_parameter_count, and raise_unless_namo_context are gone (now Formulae's). expected_argument_counts sources the count from @formulae.required_parameter_count and the fixed-vs-variadic check from @formulae[name].arity.
339
+ 1. ~ lib/Namo/Formulae.rb: + derive(name, row, namo, *arguments), the formula resolver — resolves a named formula to its value, the invocation mechanics lifted whole from Row's formula branch (collection-scoped formulae are called (row, namo, *arguments), row-only formulae (row)). derive over call: the receiver is the collection, not the callable, so the verb says the collection derives a value via the named rule rather than borrowing Proc#call's "invoke the receiver"; and the result is whatever the proc returns, not necessarily numeric, which a neutral verb leaves open. + required_parameter_count(name), public, a property of the stored callable. collection_scoped? and raise_unless_namo_context move in as private; the latter takes namo as a parameter rather than closing over Row's @namo. [] and []= are untouched — [] keeps its meaning, the stored callable as at 0.21.0: indexing a Formulae is storage access, not a Namo operation, so [] returning the callable carries no inconsistency with the dimension-value [] of Namo and Row — different domains, same spelling.
340
+ 2. ~ lib/Namo/Row.rb: #[] delegates formula resolution to @formulae.derive(name, self, @namo, *arguments); Row keeps only the fail-fast argument guard, the formula-vs-data dispatch (@formulae.key?), and the data fallback (@row[name]). collection_scoped?, required_parameter_count, and raise_unless_namo_context are gone (now Formulae's). expected_argument_counts sources the count from @formulae.required_parameter_count and the fixed-vs-variadic check from @formulae[name].arity. Behaviour-preserving at the usage level: row[:revenue], namo[:x] = formula, values, and selections are unchanged.
325
341
  3. + test/Namo/Formulae_test.rb: + #derive tests (row-only to value, collection-scoped with namo context, missing-namo-context raise, parameterised with arguments) and + #required_parameter_count tests (row-only, collection-scoped, parameterised, variadic). The #[] and #[]= blocks are unchanged — [] still returns the callable.
326
342
  4. ~ test/Namo/Row_test.rb: the formulae fixture is a Namo::Formulae, not a bare {} — Row now delegates formula resolution to its collaborator (call, required_parameter_count), which production always wraps (lib/namo.rb initialize). The data-only equality/match tests keep their {} literals: they never resolve a formula, so Hash#key? alone answers.
327
343
  5. ~ Namo::VERSION: /0.21.0/0.22.0/
328
344
 
329
345
  ## 20260625
330
346
 
331
- 0.21.0: + Namo::Formulae; @formulae: /Hash/Namo::Formulae/. Behaviour-preserving: no new capability, just an object for the formula collection to accrete behaviour onto later, mirroring the 0.1.0 extraction of Row.
347
+ 0.21.0: + Namo::Formulae; @formulae: /Hash/Namo::Formulae/.
332
348
 
333
- 1. + lib/Namo/Formulae.rb: + Namo::Formulae, a thin class wrapping a Hash @store. Responds to exactly the subset of Hash that lib/namo.rb and Row send the formula collection: [], []=, keys, key?, empty?, each, delete, merge, reject, dup; includes Enumerable (each yields [name, callable] pairs, giving map/select/etc. for free). Three deliberate choices: to_h returns a copy (@store.dup) so callers cannot mutate internals; ==/eql?/hash are names-only (keys.sort), matching Namo's own formula equality where two sets with the same names but different proc objects are equivalent; merge/reject/dup return a Formulae, not a Hash.
349
+ 1. + lib/Namo/Formulae.rb: + Namo::Formulae, a thin class wrapping a Hash @store. Behaviour-preserving: no new capability, just an object for the formula collection to accrete behaviour onto later, mirroring the 0.1.0 extraction of Row. Responds to exactly the subset of Hash that lib/namo.rb and Row send the formula collection: [], []=, keys, key?, empty?, each, delete, merge, reject, dup; includes Enumerable (each yields [name, callable] pairs, giving map/select/etc. for free). Three deliberate choices: to_h returns a copy (@store.dup) so callers cannot mutate internals; ==/eql?/hash are names-only (keys.sort), matching Namo's own formula equality where two sets with the same names but different proc objects are equivalent; merge/reject/dup return a Formulae, not a Hash.
334
350
  2. ~ lib/namo.rb: + the require; initialize now normalises the incoming formulae to a Formulae (Formulae.new(formulae) unless already one). This is the single behavioural seam — every existing internal construction passes a Hash and is wrapped, while operator results that now pass a Formulae (merge/dup return Formulae) pass through. No other call site changed: each sends a message Formulae answers.
335
351
  3. ~ test/namo_test.rb: the two assertions comparing the public #formulae accessor to a literal {} now assert emptiness (must_be_empty). The accessor returns a Formulae, not a Hash; the formula set being empty is the unchanged behaviour these tests pin. + two construction tests pinning the normalisation seam: a Hash given by keyword is wrapped in a Formulae, and a Formulae given by keyword passes through unchanged (same object).
336
352
  4. + test/Namo/Formulae_test.rb: + unit test pinning the three deliberate choices (to_h copy, names-only ==/eql?/hash, the Hash-compatible surface plus Enumerable map/select).
data/lib/Namo/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Namo::VERSION
3
3
 
4
4
  class Namo
5
- VERSION = '0.32.8'
5
+ VERSION = '0.32.10'
6
6
  end
data/lib/namo.rb CHANGED
@@ -368,18 +368,25 @@ class Namo
368
368
  end
369
369
  end
370
370
 
371
+ # An access's scope is held per fiber, keyed by the Namo, rather than on the Namo
372
+ # itself, so as a frozen Namo can be read and two threads reading one Namo don't
373
+ # share a scope.
371
374
  def materialising
372
- return yield if @materialised
373
- @materialised = {}
375
+ return yield if materialised_scopes.key?(self)
376
+ materialised_scopes[self] = {}
374
377
  begin
375
378
  yield
376
379
  ensure
377
- @materialised = nil
380
+ materialised_scopes.delete(self)
378
381
  end
379
382
  end
380
383
 
384
+ def materialised_scopes
385
+ Thread.current[:namo_materialised_scopes] ||= {}.compare_by_identity
386
+ end
387
+
381
388
  def values_for(dim)
382
- @materialised[dim] ||= (
389
+ materialised_scopes[self][dim] ||= (
383
390
  if data_dimensions.include?(dim)
384
391
  @data.map{|row_data| row_data[dim]}
385
392
  else
data/test/namo_test.rb CHANGED
@@ -325,6 +325,30 @@ describe Namo do
325
325
  _(namo.values(:agg, :x)).must_equal(agg: [2, 2, 2], x: [1, 2, 3])
326
326
  _(calls).must_equal 3
327
327
  end
328
+
329
+ it "reads a frozen Namo, the scope being held off the receiver" do
330
+ namo = Namo.new([{x: 1}, {x: 2}])
331
+ namo[:double] = proc{|row| row[:x] * 2}
332
+ namo[:total] = proc{|row, namo| namo.values(:double).sum}
333
+ namo.freeze
334
+ _(namo.values(:total)).must_equal [6, 6]
335
+ _(namo.coordinates(:double)).must_equal [2, 4]
336
+ _(namo.to_a).must_equal [{x: 1, double: 2, total: 6}, {x: 2, double: 4, total: 6}]
337
+ end
338
+
339
+ it "gives each thread reading one Namo a scope of its own" do
340
+ namo = Namo.new([{n: 1}])
341
+ entered, released = Queue.new, Queue.new
342
+ holder = nil
343
+ namo[:held] = proc{|row| entered << true; released.pop; row[:n]}
344
+ # :reader's formula lets the holding thread's access finish mid-way through this
345
+ # one, which must leave this access's scope standing for the :n that follows.
346
+ namo[:reader] = proc{|row| released << true; holder.join; row[:n]}
347
+ holder = Thread.new{namo.values(:held)}
348
+ entered.pop
349
+ _(namo.values(:reader, :n)).must_equal(reader: [1], n: [1])
350
+ _(holder.value).must_equal [1]
351
+ end
328
352
  end
329
353
 
330
354
  describe "#to_h" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namo.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.8
4
+ version: 0.32.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran