Closed alabeli closed 3 years ago
The last usage of lubridate function is this one sample_date <- ymd(mdy_hms(sample_string))
. You need to report if anything is wrong with that statement.
One wrong thing is that ymd
is a parsing function. You need as_date
there. as_date(mdy_hms(sample_string))
.
If you can cut all the code down and report the result mdy_hms(sample_string))
before and after calling Model, then we might be able to help.
Hello,
Thank you for your response. I will use as_date instead of ymd as per your suggestion, thank you for pointing that out.
Sorry I wanted to provide complete context so provided the entire code. I was able to understand from Gurobi that when I call Model
class, it silently changes locale of my R process. So I should reset locale vars after I call Model()
. LC_TIME
was getting reset to "C" instead of "en_US.UTF-8".
For anyone who may face this issue, running Sys.setlocale(category="LC_ALL", locale="en_US.UTF-8")
after calling Model()
solved the issue.
Thank you for your time. Closing this issue.
Apologies for not being able to reproduce my example using reprex since my issue involves using
gurobipy
in R which needs a proprietary license.I am using
reticulate (v1.18)
to use python'sgurobipy
package that supportsgurobi 9.1.1
. Once I callModel()
class fromgurobipy
and then if I runlubridate
functions likeymd()
ormdy_hms()
orguess_formats()
, the behavior of as.Date("year-weeknumber-dayofweek", format = "%Y-%U-%A") changes. Please note, only few functions fromlubridate
conflicts withModel()
. In my knowledge, I have had issues with the 3 mentioned here.Example in words:
Example in code:
Just as a note, python returns "2015-12-29" consistently before or after running
Model()
which is different from "2016-01-05". I was also expecting the date "2015-12-29" as output from as.Date() but I think that's a separate issue.It will be very helpful if you could explain what could be going on here. For now, I am using
ISOweek
package which gives consistent performance even after callingModel()
and using somelubridate
functions. I have also contactedgurobi
in parallel but some insight into this will help me much.lubridate
version is 1.7.9tidyverse
version is 1.3.0base
version is 3.6.3Happy to provide more information as required.
Problem
Gurobipy's
Model
class alters behavior of date formatting in R when used withlubridate
functionsymd
and/ormdy_hms
.Reproducible example
Before calling Model()
We want to correct a date
2016-01-01
to align withTuesday
as the day of the week. Below code achieves that using %Y (year), %U (week number), and %A (day of week). The value ofstart_date_sample
after running the below chunk is2016-01-05
Below is my code.
Output of
start_date_sample
= "2016-01-05"Python version
Same format argument gives a different result in python.
Call Model() of gurobipy
After calling Model()
Below chunk gives output of
start_date_sample
as NA. If you refresh the session, commentsample_date
assignment line and uncomment the line that is already commented, you will get the desired output of2016-01-05
.Output of
start_date_sample
= NAPython version
Python output is unchanged after calling
Model()
.