Skip to content

output real numbers for Eccentricity, MajorAxisLength, and MinorAxisLength - #20

Merged
joefutrelle merged 2 commits into
mainfrom
fix-complex-output
Jul 23, 2026
Merged

output real numbers for Eccentricity, MajorAxisLength, and MinorAxisLength#20
joefutrelle merged 2 commits into
mainfrom
fix-complex-output

Conversation

@joefutrelle

Copy link
Copy Markdown
Contributor

This PR fixes a bug where complex numbers (with 0 imaginary part) were being written out for Eccentricity, MajorAxisLength, and MinorAxisLength.

This requires minor changes to how the features are computed, and has an impact on CSV output formatting.

  • replace the call to np.linalg.eig with a call to np.linalg.eigh (the symmetric matrix solver, which outputs real numbers)
  • guard against small negative values from rounding being fed into sqrt and returning NaN
  • write floating-point real numbers to CSV output, making precision uniform and removing 0j notation

"Golden" test output is corrected for the new output format; the numbers are the same.

@joefutrelle joefutrelle self-assigned this Jul 23, 2026
@joefutrelle
joefutrelle requested a review from johnwaalsh July 23, 2026 17:58
@joefutrelle joefutrelle added the bug Something isn't working label Jul 23, 2026
@johnwaalsh

Copy link
Copy Markdown
Member

In tests/test_regression.py I see these functions:

def _to_complex(value):
    """Parse one CSV cell into a complex number.

    Some columns (Eccentricity, MajorAxisLength, MinorAxisLength) are currently
    written as complex literals such as '(0.888+0j)'. Parsing everything as
    complex makes the comparison indifferent to that representation, so if those
    columns are later changed to emit plain floats the values still compare
    equal rather than failing spuriously.
    """
    if value is None or (isinstance(value, float) and np.isnan(value)):
        return complex(np.nan, 0)
    return complex(str(value).strip())


def _read_features(path):
    """Read a features CSV as {column: complex128 array}, preserving order."""
    df = pd.read_csv(path, dtype=str)
    return df.columns.tolist(), {
        column: np.array([_to_complex(v) for v in df[column]], dtype=np.complex128)
        for column in df.columns
    }

Should we no longer have the _to_complex function because we're no longer outputting complex values?

@joefutrelle

Copy link
Copy Markdown
Contributor Author

Yes--this is left over from trying to get the tests to work properly before the fix, and it should be corrected.

@johnwaalsh johnwaalsh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed that this works as intended on my end. Looks good to me

@joefutrelle
joefutrelle merged commit ff91b65 into main Jul 23, 2026
2 checks passed
@joefutrelle
joefutrelle deleted the fix-complex-output branch July 23, 2026 18:59
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.

2 participants