Skip to content

Timedelta string values cannot be converted with the dtype parameter #24

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

Closed
DrGFreeman opened this issue Mar 12, 2021 · 2 comments · Fixed by #74
Closed

Timedelta string values cannot be converted with the dtype parameter #24

DrGFreeman opened this issue Mar 12, 2021 · 2 comments · Fixed by #74
Labels
testing Related to testing or lack thereof wontfix This will not be worked on

Comments

@DrGFreeman
Copy link
Owner

Timedelta string values stored in a table cannot be converted with the dtype parameter of the get_df and to_df functions or using the dataframe astype method. This is due to a known bug in pandas (ref.: pandas-dev/pandas#38509).

As a result, unit tests for the dtype parameter of the get_df and put_df function do not test this conversion. Once the pandas issue is resolved, this conversion can be added to the tests.

As a workaround, the Timedelta columns can be converted using pd.to_timedelta(df.column_name).

@DrGFreeman DrGFreeman added wontfix This will not be worked on testing Related to testing or lack thereof labels Mar 12, 2021
@DrGFreeman
Copy link
Owner Author

Tests to update:

# "C": "timedelta64[ns]", # Ref. #24

# C="timedelta64[ns]", # Ref. #24

@DrGFreeman
Copy link
Owner Author

Docs to update:

  • README.md
  • docs/overview.rst
  • .. note:: Due to a
    `known bug in pandas <https://github.com/pandas-dev/pandas/issues/38509>`_,
    timedelta strings cannot currently be converted back to timedelta64 type via the
    ``dtype`` parameter. Use the ``pandas.to_timedelta`` function instead:
    >>> df.play_time = pd.to_timedelta(df.play_time)
    >>> df.info()
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 2 entries, 0 to 1
    Data columns (total 5 columns):
    # Column Non-Null Count Dtype
    --- ------ -------------- -----
    0 bonus_points 1 non-null Int8
    1 player_id 2 non-null object
    2 last_play 2 non-null datetime64[ns, UTC]
    3 rating 2 non-null float64
    4 play_time 2 non-null timedelta64[ns]
    dtypes: Int8(1), datetime64[ns, UTC](1), float64(1), object(1), timedelta64[ns](1)
    memory usage: 196.0+ bytes

DrGFreeman added a commit that referenced this issue Feb 17, 2024
Include timedelta64 type in tests with dtype conversion. Mark the tests
as skipped for tests with pandas < 1.5 (pandas bug fixed in 1.5 and up).
DrGFreeman added a commit that referenced this issue Feb 17, 2024
Uncomment the timedelta64 dtype conversion in docs examples and update
note to indicate the pandas bug applies to pandas versions < 1.5 only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to testing or lack thereof wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant