You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Describe the feature
spec1 == spec2orcopy.copy(spec)either fail or produce unsafe shallow references.GenericSpectrogramfor the==operator and the standard library'scopymodule would improve usability. Object comparison is essential for unit testing, and safe duplication is critical for multi-step scientific workflows.Proposed solution
__eq__dunder method onGenericSpectrogramthat safely compares thedataarrays usingnp.array_equal()and checks for equality across themetadictionary (safely handling nested arrays liketimesandfreqs).__copy__and__deepcopy__dunder methods to correctly instantiate a newself.__class__with duplicated underlyingdataandmetaobjects, ensuring thatcopy.copy(spec)functions safely without side effects.