raphaelvallat/yasa

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

raphaelvallat opened this issue · 3 comments

@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.

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).

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.

YES enthusiastic support.

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