raphaelvallat / yasa

YASA (Yet Another Spindle Algorithm): a Python package to analyze polysomnographic sleep recordings.
https://raphaelvallat.com/yasa/
BSD 3-Clause "New" or "Revised" License
417 stars 113 forks source link

Change string representation of the yasa.Hypnogram class (__repr__) #128

Closed raphaelvallat closed 1 year ago

raphaelvallat commented 1 year ago

@remrama I was thinking that to avoid any confusion, we could change the string representation of the yasa.Hypnogram class to not print the pandas.Series but instead some general statistics, a la mne.Raw

def __repr__(self):
    # return f"{self.hypno}"
    return (
        f"<yasa.Hypnogram | A {self.duration} minutes hypnogram, with {self.n_stages} stages and {self.freq} resolution>\n"
        " - Use `.hypno` to get the values as a pandas.Series"
    )

which gives:

image

I still think that I prefer the original output as a shortcut to the pandas.Series, but would be ready to change if you feel strongly about this new approach.

remrama commented 1 year ago

YES enthusiastic support. This confused me about the Hypnogram class at first, but got used to it. I still was tempted sometimes to try and apply Pandas methods to the Hypnogram object :/

This avoids confusion but also has the benefit of providing more information in the string (you're example here is already useful and would be enough tbh).

remrama commented 1 year ago

I still think that I prefer the original output as a shortcut to the pandas.Series

Oh I see what you mean now -- that you would still have the pandas.Series view when viewing yasa.Hypnogram interactively (without print). Hmm, I could see it either way, but I think for clarity it makes sense to have this string representation there as well. No strong opinion though! Whatever you think is good.

raphaelvallat commented 1 year ago

YES enthusiastic support.

I'll make the change then :) I think it will be confusing to users otherwise.