Skip to content

Boolean AttributeError in Array Comparison inside psd.BinnedPSD( ) #37

@giacom0rovers1

Description

@giacom0rovers1

Description

The method __eq__ of pytmatrix.psd.BinnedPSD( ) fails with an AttributeError: 'bool' object has no attribute 'all()' if bin_edges is provided as list:

return len(self.bin_edges) == len(other.bin_edges) and \
            (self.bin_edges == other.bin_edges).all() and \
            (self.bin_psd == other.bin_psd).all()

Cause

If self.bin_edges and other.bin_edges are NumPy arrays, self.bin_edges == other.bin_edges returns an array of booleans, where .all() is valid.

However, if they are Python lists, self.bin_edges == other.bin_edges directly returns a single bool, which does not have an .all() method.

Suggested Fix

Replace the element-wise comparisons with np.array_equal(), which ensures a single boolean output regardless of input type:

return len(self.bin_edges) == len(other.bin_edges) and \
            np.array_equal(self.bin_edges, other.bin_edges) and \
            np.array_equal(self.bin_psd, other.bin_psd)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions