Skip to content

Fix TensorFrame & make it preserve column order#126

Open
engintoklu wants to merge 1 commit intomasterfrom
fix/tensorframe
Open

Fix TensorFrame & make it preserve column order#126
engintoklu wants to merge 1 commit intomasterfrom
fix/tensorframe

Conversation

@engintoklu
Copy link
Copy Markdown
Collaborator

@engintoklu engintoklu commented Apr 14, 2026

Before this pull request, TensorFrame had these issues:

  • one could add a column to a TensorFrame even if the TensorFrame had a compatible number of rows with the newly added tensor;
  • operations like adding or dropping a column resulted in non-deterministic order of columns.

This pull request fixes these mentioned issues.

Summary by CodeRabbit

  • New Features

    • Added optional size validation for tensor operations to verify dimensional compatibility.
  • Improvements

    • Column assignments now automatically validate size compatibility with existing frame data.
    • Enhanced column ordering consistency and verification in frame operations.

Before this commit, TensorFrame had these issues:
(i) one could add a column to a TensorFrame even
if the TensorFrame had a compatible number of rows
with the newly added tensor;
(ii) operations like adding or dropping a column
resulted in non-deterministic order of columns.

This commit fixes these mentioned issues.
@engintoklu engintoklu self-assigned this Apr 14, 2026
@engintoklu engintoklu added the bug Something isn't working label Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c100e780-fe20-4389-9344-ee40e3579b7c

📥 Commits

Reviewing files that changed from the base of the PR and between cebcac4 and 67692b6.

📒 Files selected for processing (2)
  • src/evotorch/tools/tensorframe.py
  • tests/test_tensorframe.py

📝 Walkthrough

Walkthrough

Extended TensorFrame.as_tensor() with a validate_size parameter for leftmost-dimension compatibility checking. Introduced _OrderedSet helper class to replace native set() for column comparisons, preserving insertion order. Updated __setitem__ to validate assigned column values at assignment time.

Changes

Cohort / File(s) Summary
Core TensorFrame enhancements
src/evotorch/tools/tensorframe.py
Added validate_size parameter to as_tensor() method with logic to check non-scalar results match frame's leftmost dimension. Introduced _OrderedSet class for order-preserving set operations. Updated __setitem__() to enforce size validation on column assignment. Refactored column-handling methods (drop(), with_columns(), Picker.__setitem__()) to use _OrderedSet instead of native set().
Test coverage updates
tests/test_tensorframe.py
Modified test_with_columns() to assert exact column order instead of unordered membership. Added test_drop() covering column removal, result verification, and error handling for invalid column references.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With ordered sets so neat and true,
And sizes validated through and through,
Our tensors align in perfect ranks,
A frame of order earns our thanks!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the two main objectives: fixing TensorFrame and preserving column order, which are the primary changes in this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tensorframe

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 84.84848% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.61%. Comparing base (cebcac4) to head (67692b6).

Files with missing lines Patch % Lines
src/evotorch/tools/tensorframe.py 84.84% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #126      +/-   ##
==========================================
+ Coverage   75.43%   75.61%   +0.17%     
==========================================
  Files          59       59              
  Lines        9556     9611      +55     
==========================================
+ Hits         7209     7267      +58     
+ Misses       2347     2344       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant