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

Subject age timedelta #1590

Merged
merged 8 commits into from
Nov 10, 2022
Merged

Subject age timedelta #1590

merged 8 commits into from
Nov 10, 2022

Conversation

bendichter
Copy link
Contributor

@bendichter bendichter commented Nov 10, 2022

Motivation

fix #1554

How to test the behavior?

subject = Subject(subject_id='RAT123', age=timedelta(seconds=99999))

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Have you checked our Contributing document?
  • Have you ensured the PR clearly describes the problem and the solution?
  • Is your contribution compliant with our coding style? This can be checked running flake8 from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

@codecov
Copy link

codecov bot commented Nov 10, 2022

Codecov Report

Merging #1590 (cd0e3e9) into dev (d435aa6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##              dev    #1590   +/-   ##
=======================================
  Coverage   91.30%   91.31%           
=======================================
  Files          25       25           
  Lines        2508     2510    +2     
  Branches      471      472    +1     
=======================================
+ Hits         2290     2292    +2     
  Misses        138      138           
  Partials       80       80           
Flag Coverage Δ
integration 70.47% <50.00%> (-0.06%) ⬇️
unit 84.42% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pynwb/file.py 88.00% <100.00%> (+0.06%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bendichter bendichter requested a review from rly November 10, 2022 19:39
@rly
Copy link
Contributor

rly commented Nov 10, 2022

I hesitate to homebrew ship our own solution for a timedelta -> ISO 8601 duration conversion, but this seems to be the best available and doesn't require adding a dependency.

@CodyCBakerPhD
Copy link
Collaborator

I hesitate to homebrew ship our own solution for a timedelta -> ISO 8601 duration conversion, but this seems to be the best available and doesn't require adding a dependency.

PyNWB requires pandas: https://github.com/NeurodataWithoutBorders/pynwb/blob/dev/setup.py#L25

pandas has a Timedelta to ISO functioanlity we would want:

from pandas import Timedelta

time_delta = Timedelta(days=2,weeks=1, minutes=50, seconds=12)
iso_string = time_delta.isoformat()

so all you would have to do to accommodate both that class type and datetime.timedelta is map a datetime.timedelta onto the pandas.Timedelta and it's out of our hands and safely the responsibility of upstream dependencies.

@CodyCBakerPhD
Copy link
Collaborator

And actually, as far as I can tell, pandas.Timedelta can take datetime.timedelta objects as the input.

import datetime
import pandas

time_delta = pandas.Timedelta(datetime.timedelta(days=2,weeks=1, minutes=50, seconds=12))
iso_string = time_delta.isoformat()

@bendichter
Copy link
Contributor Author

I think this is a pretty simple function and I'm pretty confident it's going to work but I'd also be fine with using pandas

@rly
Copy link
Contributor

rly commented Nov 10, 2022

Looks good to me. Thanks!

@bendichter bendichter merged commit ceffef3 into dev Nov 10, 2022
@rly rly deleted the subject_age_timedelta branch December 22, 2023 00:42
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

Successfully merging this pull request may close these issues.

[Feature]: subject.age should accept a timedelta object
3 participants