Skip to content

Bug when trying to set the unit on a TimeSeries column #8642

@astrofrog

Description

@astrofrog

When trying to set the unit on a time series column, I am running into an error:

>>> from astropy import units as u
>>> from astropy.timeseries import TimeSeries
>>> ts1 = TimeSeries(time_start='2016-03-22T12:30:31', time_delta=3 * u.s, n_samples=5)
>>> ts1['flux'] = [1,2,3,4,5]
>>> ts1['flux'].unit = 's'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-1ddfdfcdb27c> in <module>
      3 ts1 = TimeSeries(time_start='2016-03-22T12:30:31', time_delta=3 * u.s, n_samples=5)
      4 ts1['flux'] = [1,2,3,4,5]
----> 5 ts1['flux'].unit = 's'

~/Code/astropy/astropy/table/column.py in __setattr__(self, item, value)
    853             else:
    854                 if converted is not self:
--> 855                     self.parent_table.replace_column(self.name, converted)
    856 
    857     def _base_repr_(self, html=False):

~/Code/astropy/astropy/table/table.py in replace_column(self, name, col)
   1920             raise ValueError('cannot replace a table index column')
   1921 
-> 1922         t = self.__class__([col], names=[name])
   1923         cols = OrderedDict(self.columns)
   1924         cols[name] = t[name]

~/Code/astropy/astropy/timeseries/sampled.py in __init__(self, data, time, time_start, time_delta, n_samples, **kwargs)
     89 
     90         if time is None and time_start is None:
---> 91             raise TypeError("Either 'time' or 'time_start' should be specified")
     92         elif time is not None and time_start is not None:
     93             raise TypeError("Cannot specify both 'time' and 'time_start'")

TypeError: Either 'time' or 'time_start' should be specified

I haven't investigated this yet, but at first glance I'm surprised that simply setting the unit on a column causes a new TimeSeries to be instantiated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions