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

Add timedelta, timedelta64 and datetime64 plus respective conversions #509

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
093bdcb
add support for `@py from <module> import`
Feb 21, 2022
c63ab23
Merge branch 'cjdoris:main' into main
hhaensel Jul 5, 2023
5a65a52
Merge branch 'main' of https://github.com/hhaensel/PythonCall.jl
hhaensel Jun 16, 2024
5740b59
support timedelta, timedelta64, datetime64 and respective conversions
hhaensel Jun 16, 2024
f897600
fix week kw in pytimedelta64, typo (space) in builtins
hhaensel Jun 16, 2024
1e8d410
correct handling of count in 64-bit conversion rules
Jun 17, 2024
b3cc79f
Merge remote-tracking branch 'origin/main' into hh-timedelta64
hhaensel Jul 28, 2024
9dfc0dd
Apply suggestions from code review
hhaensel Sep 6, 2024
a3a2b97
Apply suggestions from code review part II
hhaensel Sep 6, 2024
daf9759
reviewers suggestions part III
hhaensel Sep 6, 2024
60e0daa
Merge branch 'JuliaPy:main' into hh-timedelta64
hhaensel Jan 19, 2025
7391b8d
add tests for pytimedelta
Jan 19, 2025
8f28567
fix micro/millisecond in pytimedelta,
Jan 20, 2025
46efe53
add tests for pytimedelta, pytimedelta64 and conversion of pytimedelt…
Jan 20, 2025
d36c113
fix pytimdelta(years/months=0), add pydatetime64(::Union{Date, DateTi…
hhaensel Jan 21, 2025
66459c6
add tests for pytimedelta64, pydatetime64
hhaensel Jan 21, 2025
3c51b54
support unitless timedelta64, keep unit per default, add keyword cano…
Jan 21, 2025
fac1ef8
add tests for timedelta64 canonicalize
Jan 21, 2025
d00a788
Merge branch 'JuliaPy:main' into hh-timedelta64
hhaensel Jan 21, 2025
5abcf1d
add CondaPkg and DataFrames as extras in Project.toml
Jan 21, 2025
34f35ce
fix pandas testing
Jan 20, 2025
9864173
fix compat with julia < 1.8
Jan 21, 2025
3148bae
specialize Base.convert(::<:Period, CompoundPeriod) for julia < 1.8
Jan 21, 2025
94b47df
change CondaPkg environment
Jan 21, 2025
f66f526
fix test/Project.toml, adapt runtests.jl
Jan 21, 2025
e9277ef
change order of args of pytimedelta; add docstrings for pytimedelta, …
Feb 19, 2025
d93e99a
remove `@py`method for python-style imports
Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix week kw in pytimedelta64, typo (space) in builtins
hhaensel committed Jun 16, 2024
commit f897600b25fedc31ce2b3c378dca61d68d1e95b0
2 changes: 1 addition & 1 deletion src/Convert/numpy.jl
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ function pytimedelta64(
year::Int=_year, month::Int=_month, day::Int=_day, hour::Int=_hour, minute::Int=_minute, second::Int=_second, microsecond::Int=_microsecond, millisecond::Int=_millisecond, nanosecond::Int=_nanosecond, week::Int=_week)
pytimedelta64(sum((
Year(year), Month(month), # you cannot mix year or month with any of the below units in python, the error will be thrown by `pytimedelta64(::CompoundPeriod)`
Copy link
Contributor

@MilesCranmer MilesCranmer Aug 23, 2024

Choose a reason for hiding this comment

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

This comment

you cannot mix year or month with any of the below units in python, the error will be thrown by pytimedelta64(::CompoundPeriod)

Should be presented to the user as a descriptive error message rather than a comment in the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe the comment isn't clear enough.
Python throws a well understandable descriptive error in case of wrong usage, so no need for us to do so. Agree?

Day(day), Hour(hour), Minute(minute), Second(second), Millisecond(millisecond), Microsecond(microsecond), Nanosecond(nanosecond))
Day(day), Hour(hour), Minute(minute), Second(second), Millisecond(millisecond), Microsecond(microsecond), Nanosecond(nanosecond), Week(week))
))
end
function pytimedelta64(@nospecialize(x::T)) where T <: Period
2 changes: 1 addition & 1 deletion src/Core/builtins.jl
Original file line number Diff line number Diff line change
@@ -1074,7 +1074,7 @@ end
function pytimedelta(@nospecialize(x::T)) where T <: Period
T <: Union{Week, Day, Hour, Minute, Second, Millisecond, Microsecond} ||
error("Unsupported Period type: ", "Year, Month and Nanosecond are not supported, consider using pytimedelta64 instead.")
args = T .== (Day, Second, Millisecond, Microsecond, Minute, Hour, Week)
args = T .== (Day, Second, Millisecond, Microsecond, Minute, Hour, Week)
pytimedelta(x.value .* args...)
end
function pytimedelta(x::CompoundPeriod)