Closed MartinPJorge closed 3 years ago
Hi Martin,
Thanks for reporting this issue. However, the problem is not in setData
but in exportData
. If you set display_eps
, and display_precision
before displaying birthday you will see the values being displayed with full precision:
print(df)
ampl.setData(df)
print('Running display birthday')
ampl.setOption('display_eps', 0)
ampl.setOption('display_precision', 0)
ampl.display('birthday')
people | birthday
'Ana' | 1590368301.4660506
'Paco' | 1590369880.8816786
'Luisa' | 1590370343.6891866
'Jose' | 1590372107.3934467
'Lucas' | 1590372547.151566
'Marta' | 1590374396.6734059
Running display birthday
birthday [*] :=
Ana 1590368301.4660506
Jose 1590372107.3934467
Lucas 1590372547.151566
Luisa 1590370343.6891866
Marta 1590374396.673406
Paco 1590369880.8816786
;
The problem here is in exportData
that indeed uses display the output the numbers to the data file. As a workaround until this issue is fixed, you will need to set display_eps
and display_precision
before exportData
.
amplpy v0.7.0 has just been released and this issue has been fixed in the internal C++ API.
Problem
I'm using amplpy version 0.6.11 installed with pip, and python3.
Let's take the following
model.mod
:and this amplpy code to create a .DAT file:
which creates the following
out.dat
:As you can see the birthday numbers have been rounded. Initially I thought this was because of
.exportData()
. But the script output was showing that although the dataframe was correct, the.setData()
function did the rounding:Solution
I have realised that this rounding misbehaviour is because
amplpy
uses the display command to write the values. Hence the problem is easy to fix by adding these lines:which will yield in stdout:
and
out.dat
:Request
Please do not make
ampl.setData()
dependant to the display precision. Values must be stored using their real value, otherwise one cannot recover them latter.