Skip to content

ENH: enable timedelta.total_seconds#3616

Merged
scoder merged 7 commits intocython:masterfrom
jbrockmendel:total_seconds
May 19, 2020
Merged

ENH: enable timedelta.total_seconds#3616
scoder merged 7 commits intocython:masterfrom
jbrockmendel:total_seconds

Conversation

@jbrockmendel
Copy link
Contributor

No description provided.

@jbrockmendel
Copy link
Contributor Author

Is the recommended way to run the tests with python3 runtests.py? Is there a way to run just the newly introduced test?

@scoder
Copy link
Contributor

scoder commented May 18, 2020

You can pass a name regex on the cmdline. I usually also pass -vv and --backend=c. And also --debug to keep the generated files around etc.

@scoder
Copy link
Contributor

scoder commented May 18, 2020

@jbrockmendel
Copy link
Contributor Author

Thanks.

It looks like this works when I make it a module-level function, but i get compile-time errors when I make it a timedelta method

Copy link
Contributor

@scoder scoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the *_DELTA_* functions aren't available in Py2. That's probably the reason why they were commented out. It's good to have them declared in the .pxd file, but we can't use them in code (yet).

@jbrockmendel
Copy link
Contributor Author

Looks like the DELTA functions aren't available in Py2 [...] but we can't use them in code (yet).

makes sense. Is py2 being dropped anytime soon?

@scoder
Copy link
Contributor

scoder commented May 19, 2020

I added the missing declarations for Py2 as a backport.

Comment on lines +93 to +95
int PyDateTime_DELTA_GET_DAYS(object o)
int PyDateTime_DELTA_GET_SECONDS(object o)
int PyDateTime_DELTA_GET_MICROSECONDS(object o)
int PyDateTime_DELTA_GET_DAYS(timedelta o)
int PyDateTime_DELTA_GET_SECONDS(timedelta o)
int PyDateTime_DELTA_GET_MICROSECONDS(timedelta o)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good idea. This will enforce type checks on caller side if the type is not known, which will either reduce the performance or make users uglify their input with type casts.

These are clearly macros, designed for speed. Let it crash if users misapply them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's not a performance hit to having it be object?

@scoder scoder merged commit cbe4327 into cython:master May 19, 2020
@jbrockmendel jbrockmendel deleted the total_seconds branch May 19, 2020 22:24
@jbrockmendel
Copy link
Contributor Author

Thanks for walking me through this. Is there a viable way to make total_seconds a timedelta method in addition to a function here?

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.

2 participants