Skip to content

✨ Implement LaserFrame.__contains__() with DataFrame-style property/column membership - #422

Merged
clorton merged 2 commits into
mainfrom
property-in-laserframe
Jun 29, 2026
Merged

clorton merged 2 commits into
mainfrom
property-in-laserframe

Conversation

@clorton

@clorton clorton commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Rationale

Some "syntactic sugar" that is useful for validation ("my component needs this property to exist on the LaserFrame to work correctly") or customization ("if no one else has added this property, then I will so my component can function correctly").

Adds a __contains__ method that returns True for property names and non-underscored kwargs-set attributes, and False for underscored backing
arrays, internal state, methods, class-level descriptors, and non-string items. Includes ten new tests covering the full contract.

Fixes #275

@clorton clorton added this to the M3: LASER 1.1 milestone Jun 23, 2026
@clorton
clorton requested review from Copilot and jonathanhhb June 23, 2026 22:44
@clorton clorton self-assigned this Jun 23, 2026
@clorton clorton added the enhancement New feature or request label Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds DataFrame-like column membership semantics to LaserFrame via a new __contains__ implementation, enabling safe checks like "age" in lf for properties and selected instance attributes.

Changes:

  • Implement LaserFrame.__contains__ to return True for registered property names and non-underscored instance attributes, and False for non-strings and underscored/internal instance attributes.
  • Add a new test suite covering in behavior for scalar/vector/array properties, kwargs-set attributes, unknown names, non-string items, and class-level methods/properties.
  • Document the new membership semantics in CHANGELOG.rst.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/laser/core/laserframe.py Adds __contains__ to provide column-style membership checks against _properties and non-underscored instance attributes.
tests/test_laserframe.py Adds new tests pinning the intended __contains__ contract and preventing regression to the prior super().__contains__ error.
CHANGELOG.rst Describes the new LaserFrame.__contains__ semantics and their intent for callers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_laserframe.py Outdated
Comment thread CHANGELOG.rst Outdated
Comment thread src/laser/core/laserframe.py Outdated
@clorton
clorton force-pushed the property-in-laserframe branch from 4ecc72a to 08c0ca5 Compare June 24, 2026 20:16
@clorton clorton changed the title ✨ Implement LaserFrame.__contains__ with DataFrame-style column membership ✨ Implement LaserFrame.__contains__ with DataFrame-style property/column membership Jun 24, 2026
@clorton clorton changed the title ✨ Implement LaserFrame.__contains__ with DataFrame-style property/column membership ✨ Implement LaserFrame.__contains__() with DataFrame-style property/column membership Jun 24, 2026
@clorton
clorton force-pushed the property-in-laserframe branch from 08c0ca5 to 1334156 Compare June 25, 2026 20:51
Comment thread src/laser/core/laserframe.py Outdated
return self._count

def __contains__(self, item) -> bool:
# Column-style membership: True for any name LaserFrame's documented access

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT thought the doc string could be tweaked to emphasize the most surprising element of the design (allowing preceding underscores to be treated the regular attributes). I of course understand why we're doing this but GPT thought it's genuinely a little surprising to a python-trained mind.

Image

For your consideration. Otherwise all makes sense.

@jonathanhhb jonathanhhb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Request change" is more "consider slight doc string change". Not required.

membership

Adds a `__contains__` method that returns `True` for property names and
non-underscored kwargs-set attributes, and `False` for underscored
backing
arrays, internal state, methods, class-level descriptors, and non-string
items. Includes ten new tests covering the full contract.
@clorton
clorton force-pushed the property-in-laserframe branch from 1334156 to b59b77b Compare June 29, 2026 23:23
@clorton
clorton merged commit d39397f into main Jun 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider supporting "property" in LaserFrame

3 participants