Skip to content

Three more documented rules for a named shift offset are unenforced, and one of them crashes the typesetter #62

Description

@FBumann

What happened?

Split out of #58, which covered the two rules a named offset shares with a window's width. shift(offset=p) documents four rules plus a sign rule. Two are fixed in #61; these three are not.

1. A negative named offset crashes instead of being refused — the important one

The docs say:

A named offset also carries its sign in the values: lag=-lead is refused, so one row that points backwards says so where the data is read.

walk.py relies on this in two places:

A named offset comes back as its name. It is always backward — the language refuses by=-p, so the direction lives in the data

It is not refused. It loads, and then the typesetter dies:

parameters: { lead: { dims: [unit], dtype: int } }
constraints:
  c:
    foreach: [unit, hour]
    expression: x <= shift(x, over=hour, offset=-lead, edge='wrap')
load:    OK
typeset: AssertionError            # bare, from _amount() in walk.py

_amount asserts isinstance(node.operand, NumberNode) after matching a UnaryOperatorNode, so a negated parameter trips the assert. Two things wrong: the language rule isn't enforced, and the failure is an assertion rather than a LanguageError with a sentence.

This is also load-bearing for #56/#59: the reason sum_forward must exist as an operator rather than a composition is that offset=-(p-1) is refused. Right now it isn't refused, it just breaks later.

2. An offset must vary only over dims the shift can read it at

it varies only over dims the shift can read it at — the shifted expression's own, or the one a by= lookup groups into. An offset is read at the coordinate it moves, and a dimension that coordinate does not have is no coordinate at all

Unenforced: a parameter over a dimension unrelated to the operand loads clean.

3. A named offset requires an edge=

it says what the vacated positions contribute — edge='wrap' or a number. The bare form's absence is carried by a frame keyed by the translated dimension alone, and a per-entity offset vacates a different slot for each entity, which that frame cannot yet say.

Unenforced: shift(x, over=hour, offset=lead) with no edge= loads clean.

What it should be

All three as load errors in the language's own wording. (1) should also stop being an assertion — _amount's precondition becomes true only once the rule is enforced, so the check and the assert belong in the same change.

_check_named_amount in dimensions.py (added by #61) is the natural home for (2); (1) and (3) are call-shape facts and may fit resolution.py better, where arity is already checked.

Version

v0.0.0-alpha.10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: conformanceCode and the documented spec disagree

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions