Skip to content

Error with yasa.plot_hypnogram with 1Hz sampling rate #223

@roohy466

Description

@roohy466

Hi
I am using Yasa 0.6.5.
if I use sf_hypno=0.999999999 in the yasa.plot_hypnogram, it works but with sf_hypno=1 , it gives the following error

python_virtual_env/lib/python3.13/site-packages/yasa/plotting.py:89: FutureWarning: 'S' is deprecated and will be removed in a future version. Please use 's' instead of 'S'.
  freq_str = pd.tseries.frequencies.to_offset(pd.Timedelta(1 / sf_hypno, "S")).freqstr
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[35], line 41
     39 data = raw.get_data(units="uV")
     40 hypno_up = yasa.hypno_upsample_to_data(hypno, sf_hypno=1, data=data, sf_data=raw.info['sfreq'])
---> 41 yasa.plot_hypnogram(hypno,highlight="N2",sf_hypno=1)

File ~/python_virtual_env/lib/python3.13/site-packages/yasa/plotting.py:91, in plot_hypnogram(hyp, sf_hypno, highlight, fill_color, ax, **kwargs)
     89     freq_str = pd.tseries.frequencies.to_offset(pd.Timedelta(1 / sf_hypno, "S")).freqstr
     90     # Create Hypnogram instance for plotting
---> 91     hyp = Hypnogram(hypno_int_to_str(hyp), freq=freq_str)
     93 # Work with a copy of the Hypnogram to not alter the original
     94 hyp = hyp.copy()

File ~/python_virtual_env/lib/python3.13/site-packages/yasa/hypno.py:277, in Hypnogram.__init__(self, values, n_stages, freq, start, scorer)
    275 self._n_epochs = hypno.shape[0]
    276 self._freq = freq
--> 277 self._sampling_frequency = 1 / pd.Timedelta(freq).total_seconds()
    278 self._start = start
    279 self._timedelta = timedelta

File pandas/_libs/tslibs/timedeltas.pyx:1844, in pandas._libs.tslibs.timedeltas.Timedelta.__new__()

File pandas/_libs/tslibs/timedeltas.pyx:647, in pandas._libs.tslibs.timedeltas.parse_timedelta_string()

ValueError: unit abbreviation w/o a number

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