Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
259 changes: 0 additions & 259 deletions src/datetime.h

This file was deleted.

14 changes: 7 additions & 7 deletions src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ using namespace Rcpp;
#include "event_loop.h"
#include "tinythread.h"

#include "datetime.h"

#include <fstream>
#include <time.h>

Expand Down Expand Up @@ -1704,9 +1702,7 @@ void py_initialize(const std::string& python,

// poll for events while executing python code
event_loop::initialize();

// create static variable PyDateTimeAPI used by macros in datetime.h
PyDateTime_IMPORT;

}

// [[Rcpp::export]]
Expand Down Expand Up @@ -2424,7 +2420,11 @@ PyObjectRef r_convert_dataframe(RObject dataframe, bool convert) {
// [[Rcpp::export]]
PyObjectRef r_convert_date(Date date, bool convert) {

PyObject* py_date = PyDate_FromDate(date.getYear(), date.getMonth(), date.getDay());
PyObject* datetime = PyImport_ImportModule("datetime");
PyObject* py_date = PyObject_CallMethod(
datetime, "date", "iii", date.getYear(), date.getMonth(), date.getDay());

@kevinushey kevinushey Nov 15, 2019

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very pedantic nitpick: you may want to explicit cast date.getYear() and friends to int, e.g.

static_cast<int>(date.getYear())

While the getYear() method does produce an int, in general, when using variadic C functions, it's good practice to cast arguments to ensure they match the type expected / declared in the format string.

The code is correct as is, but I just want to call it out as a kind of best practice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done!

if (py_date == NULL) {
stop(py_fetch_error());
}
return py_ref(py_date, convert);

}