Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pluma.io.empatica.py, 'E4_Seconds' and 'Seconds' column dtype is <M8[ns], not datetime #72

Open
NeuroThom opened this issue Oct 29, 2024 · 1 comment

Comments

@NeuroThom
Copy link

In pluma.io.empatica.py, parse_empatica_stream(), 'E4_Seconds' is used as a DatetimeIndex in one case:

df.index = pd.DatetimeIndex(df["E4_Seconds"] + clock_offset, name=df.index.name)

But has dtype of <M8[ns] in these cases:

df["E4_Seconds"] = _EMPATICA_T0 + pd.to_timedelta(df["E4_Seconds"].values.astype(float), "s")

df["E4_Seconds"] = _EMPATICA_T0 + pd.to_timedelta(df["E4_Seconds"].values.astype(float), "s")

Consider using pandas.datetime in these cases for consistency in data processing methods later, without the need to convert, for example to resample data using df = df.set_index('E4_seconds').resample("1S").mean().reset_index()

@glopesdev
Copy link
Member

glopesdev commented Nov 11, 2024

@NeuroThom sorry I was a bit confused in the end about which one you recommend we should use, is it pd.DatetimeIndex or pd.to_timedelta? From the text I am assuming it should be pd.DatetimeIndex but just wanted to be sure.

I believe the types in the lines you quoted might have been left there for backwards compatibility, or to provide access to unconverted raw data, not entirely sure. If clock_offset is defined, the conversion to pd.Datetime is already there. Expanding your two examples for context:

df["E4_Seconds"] = _EMPATICA_T0 + pd.to_timedelta(df["E4_Seconds"].values.astype(float), "s")
if clock_offset is not None:
df.index = pd.DatetimeIndex(df["E4_Seconds"] + clock_offset, name=df.index.name)

df["E4_Seconds"] = _EMPATICA_T0 + pd.to_timedelta(df["E4_Seconds"].values.astype(float), "s")
if clock_offset is not None:
df.index = pd.DatetimeIndex(df["E4_Seconds"] + clock_offset, name=df.index.name)

Is the recommendation that we simply define a default clock_offset, e.g. 0, if no known offset is provided? Not sure in which cases would a clock_offset not be defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants