Skip to content

[Bug]: TimeSeries.get_timestamps fails for numpy array timestamps #2180

@pauladkisson

Description

@pauladkisson

What happened?

I was trying to use the new convenience method on the TimeSeries class, get_timestamps, and it threw an error on my time series, which use numpy arrays for timestamps.

Steps to Reproduce

time_series = mock_TimeSeries(data=[1, 2, 3], timestamps=np.array([3, 4, 5]), rate=None)
assert_array_equal(time_series.get_timestamps(), [3, 4, 5])

Traceback

def get_timestamps(self):
        """
        Get the timestamps of this TimeSeries. If timestamps are not stored in this TimeSeries, generate timestamps.
        """
>       if self.fields.get('timestamps'):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

src/pynwb/base.py:396: ValueError

Operating System

macOS

Python Executable

Conda

Python Version

3.13

Package Versions

No response

Code of Conduct

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