Skip to content

Implement __eq__ , __copy__, and __deepcopy__ for GenericSpectrogram. #186

@MohamedAli1937

Description

@MohamedAli1937

Describe the feature

  • Comparing two spectrograms or creating an exact duplicate is cumbersome, as standard Python operations like spec1 == spec2 or copy.copy(spec) either fail or produce unsafe shallow references.
  • Adding native support in GenericSpectrogram for the == operator and the standard library's copy module would improve usability. Object comparison is essential for unit testing, and safe duplication is critical for multi-step scientific workflows.

Proposed solution

  • Implement an __eq__ dunder method on GenericSpectrogram that safely compares the data arrays using np.array_equal() and checks for equality across the meta dictionary (safely handling nested arrays like times and freqs).
  • Implement __copy__ and __deepcopy__ dunder methods to correctly instantiate a new self.__class__ with duplicated underlying data and meta objects, ensuring that copy.copy(spec) functions safely without side effects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions