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

ENH: enable timedelta.total_seconds #3616

Merged
merged 7 commits into from May 19, 2020
Merged

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).

Cython/Includes/cpython/datetime.pxd Outdated Show resolved Hide resolved
@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.

Cython/Includes/cpython/datetime.pxd Outdated Show resolved Hide resolved
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.

None yet

2 participants