-
Notifications
You must be signed in to change notification settings - Fork 327
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
passing dates or datetime.date objects as parameters #198
Comments
Thanks for the bug report! This is primarily because we transform R
I believe this is typically the behaviour you want when manipulating e.g. Dates that live as part of a Pandas DataFrame, or as a vector / list of dates, but it does fail when one attempts to manipulate with plain old Python datetime objects. I'm still not 100% sure whether we've made the right choice, though. Perhaps Date objects should be coerced into Python datetime objects? Maybe only times (e.g. |
I'm very biased, but it would be cool to have some way to get to python datetime objects. I haven't played around with reticulate enough to investigate if there's an awkward workaround, which would be sufficient. I could also just write wrappers which converts the strings to dates in python and then passes arguments along within python, which may be best if this is a small use case generally. I'm thankful for this package and the comment! |
For context, we make the conversion here: Lines 125 to 146 in 897c65d
Perhaps there's a better way we could decide whether we should produce a Python datetime vs. a NumPy datetime64? Maybe we should only convert dates / times contained within a data frame to a NumPy |
@terrytangyuan I'm curious what you think re: choosing Python |
I am all in for more performant conversion (I like the current default and fallback behavior) but I don't think this is 100% what the users might want. Perhaps we should expose this as an option? |
I just ran into this issue. The current choice makes sense if the primary purpose is to convert R data frames into Pandas data frames. However, when calling Python functions it is necessary to have exact control over the resulting type produced by The current documentation says that single element R vector will be converted to a Python scalar (https://rstudio.github.io/reticulate/articles/calling_python.html). This suggests that a single What about exposing explicit converters, e.g. Lines 133 to 145 in 897c65d
|
Thanks for the comments, everyone. I think we should adopt the following convention:
Does this sound reasonable? Note that I'm exploring this as part of #259. Note that doing this also somewhat relieves |
Just as an aside, we can't fully map to datetime64 as we only have 53 bits in POSIXct. That was one of the reasons I started the nanotime package which lives on top of I think the route via |
I think POSIXct <-> datetime64 as a default is at least sensible, but given that we do risk losing precision we may want to provide some APIs for using Maybe we need some extensions to A similar argument could probably be made for |
Yes, a hook to permit extensions seems sensible, as does the suggested default. The added converters always pull a tail of other packages in: |
Following up on this, it seems the (possibly new?) convert=FALSE parameters do the trick. For a scalar date, i can do the below:
...and for the more general case, #259 is already merged. I'll close this. |
Not sure if this is considered a good reprex example for reticulate, but let me try this.
I'm having issues using datetime.date objects as parameters into my python scripts, where they become floats in the process Per the below, a datetime.date object as a default parameter works, passing it in does not, and returning the value returns the integer equivalent. Thoughts on how to pass a date to a function?
test.py:
Then in R...
Created on 2018-03-26 by the reprex package (v0.2.0).
The text was updated successfully, but these errors were encountered: