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

ValueError: time data "2019-11-02T07:10:53+01:00" doesn't match format "%Y-%m-%d %H:%M:%S", at position 0 #54

Closed
taoofstefan opened this issue Apr 20, 2023 · 2 comments

Comments

@taoofstefan
Copy link

taoofstefan commented Apr 20, 2023

Hey,

I am using the code below, in VS Code, to get my Oura data into df. This works fine for the readiness_df. When I try it for the combined_df_edited, I get an error.

import pandas as pd
from datetime import date, timedelta
from oura import OuraClientDataFrame
from api_token import API_TOKEN

oura_token = API_TOKEN # Your Oura token
client = OuraClientDataFrame(personal_access_token=oura_token) # Make connection

start = '2018-11-01'
days = 7
week_past = str(date.today() - timedelta(days))

readiness_df = client.readiness_df(start=start)
print(readiness_df.head())
combined_df = client.combined_df_edited(start=start)

Error:

`Traceback (most recent call last):
  File "c:\Users\stefa\OneDrive\Coding\Oura\test.py", line 22, in <module>
    combined_df = client.combined_df_edited(start=start)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\stefa\AppData\Local\Programs\Python\Python311\Lib\site-packages\oura\client_pandas.py", line 198, in combined_df_edited
    sleep_df = self.sleep_df(start, end, metrics)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\stefa\AppData\Local\Programs\Python\Python311\Lib\site-packages\oura\client_pandas.py", line 104, in sleep_df
    return SleepConverter(convert_cols).convert_metrics(df)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\stefa\AppData\Local\Programs\Python\Python311\Lib\site-packages\oura\converters.py", line 119, in convert_metrics
    df = super().convert_metrics(df)
tools\datetimes.py", line 1050, in to_datetime
    values = convert_listlike(arg._values, format)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\stefa\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\tools\datetimes.py", line 453, in _convert_listlike_datetimes
    return _array_strptime_with_fallback(arg, name, utc, format, exact, errors)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\stefa\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\tools\datetimes.py", line 484, in _array_strptime_with_fallback
    result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\_libs\tslibs\strptime.pyx", line 530, in pandas._libs.tslibs.strptime.array_strptime
  File "pandas\_libs\tslibs\strptime.pyx", line 351, in pandas._libs.tslibs.strptime.array_strptime
ValueError: time data "2019-11-02T07:10:53+01:00" doesn't match format "%Y-%m-%d %H:%M:%S", at position 0. You might want to try:
    - passing `format` if your strings have a consistent format;
    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.`

I switched to VS code. Interestingly, this doesn't happen if I run the code in Spyder. I simply get the data without error as expected.

I have no idea why. Do you guys have any ideas about what's wrong?

@urasaku77
Copy link

Hello. I also encountered the same bug. The cause is likely that this library is not compatible with the latest version of pandas.

Initially, I was using pandas 2.0.x, but when I downgraded to version 1.5.3 and ran it, the error disappeared, and it started functioning properly. Please give it a try.

@taoofstefan
Copy link
Author

Thanks for this tip! I don't know what was the exact problem, but I created a new virtual environment in Anaconda with only the basic modules. Now it's running fine, in VS Code and Spyder.

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