-
Notifications
You must be signed in to change notification settings - Fork 346
use Rcpp to convert R Dates to Python #643
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1702,6 +1702,7 @@ void py_initialize(const std::string& python, | |
|
|
||
| // poll for events while executing python code | ||
| event_loop::initialize(); | ||
|
|
||
| } | ||
|
|
||
| // [[Rcpp::export]] | ||
|
|
@@ -2415,3 +2416,15 @@ PyObjectRef r_convert_dataframe(RObject dataframe, bool convert) { | |
| return py_ref(dict.detach(), convert); | ||
|
|
||
| } | ||
|
|
||
| // [[Rcpp::export]] | ||
| PyObjectRef r_convert_date(Date date, bool convert) { | ||
|
|
||
| PyObject* datetime = PyImport_ImportModule("datetime"); | ||
| PyObject* py_date = PyObject_CallMethod( | ||
| datetime, "date", "iii", date.getYear(), date.getMonth(), date.getDay()); | ||
|
||
| if (py_date == NULL) { | ||
| stop(py_fetch_error()); | ||
| } | ||
| return py_ref(py_date, convert); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may need to handle length-one lists still (to ensure they're returned as scalars)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure exactly what you mean? I was trying to find what this
reticulate/R/conversion.R
Line 172 in 64f685a
was for but didn't manage to get into the
elsebranch...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g.
That is, we make a Python list for R vectors of length > 1, and a 'scalar' for R vectors of length 1. Is this behavior still preserved in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, got it, thanks! Does this look better now?