Hi Jernej,

This is a floating point representation issue.  With 32 bits,
the representations of
the numbers you want are as given.  You can see the same issue if you look
closely
with numpy.  Observe the last couple of digits:

In [1]: import numpy as np

In [2]: np.array([12.12, 12.1234567], 'f4')
Out[2]: array([ 12.11999989,  12.12345695], dtype=float32)

If you want to 'fix' this issue, you should bump up the precision to 64
bits by using
Float64Cols.  The equivalent in numpy is:

In [7]: np.array([12.12, 12.1234567], 'f8')
Out[7]: array([ 12.12     ,  12.1234567])

Also I would recommend reading this:
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Be Well
Anthony


On Mon, Oct 22, 2012 at 9:36 AM, Jernej Makovsek
<jernej.makov...@gmail.com>wrote:

> Hi.
> pyTables saves wrong data to file. I read the docs, but I don't know what
> I'm doing wrong. It's the first time I noticed this kind of behavior. Any
> suggestions?
>
> *problem: *
> writing items in testL = [12.12, 12.1234567] to table
> data in table: col1 = 12.1199998856, col2 = 12.1234569550
> expected: col1 = 12.12, col2 = 12.1234567
>
> *script:*
> class MyDescrClass(IsDescription):
>     eventDate = Float64Col()
>     col1 = Float32Col()
>     col2 = Float32Col()
>
> newdb = "_misc/db/test.h5"
> dbFilters = tables.Filters(complevel=9, complib='blosc', shuffle=1)
> h5file = tables.openFile(db, filters=dbFilters, mode="a")
>
> testL = [12.12, 12.1234567]
> print("data in list: %.10f, %.10f" % (testL[0], testL[1]))
>
> newh5file = tables.openFile(newdb, filters=dbFilters, mode="a")
> newh5file.createTable(newh5file.root, "myTable", MyDescrClass,
> "someTitle", filters=dbFilters, expectedrows=1000000000)
>
> testT = newh5file.root.myTable
> testT.row["col1"] = testL[0]
> testT.row["col2"] = testL[1]
> testT.row["eventDate"] = 1311530521.215325
> testT.row.append()
> testT.flush()
>
> for row in testT:
>     print("data in table: col1 = %.10f, col2 = %.10f" % (row["col1"],
> row["col2"]))
> newh5file.close()
>
> *output:*
> data in list: 12.1200000000, 12.1234567000
> data in table: col1 = 12.1199998856, col2 = 12.1234569550
>
>
> tables.print_versions()
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> PyTables version:  2.4.0
> HDF5 version:      1.8.4-patch1
> NumPy version:     1.6.1
> Numexpr version:   1.4.2 (not using Intel's VML/MKL)
> Zlib version:      1.2.3.4 (in Python interpreter)
> BZIP2 version:     1.0.6 (6-Sept-2010)
> Blosc version:     1.1.3 (2010-11-16)
> Cython version:    0.15.1
> Python version:    2.7.3 (default, Aug  1 2012, 05:14:39)
> [GCC 4.6.3]
> Platform:          linux2-x86_64
> Byte-ordering:     little
> Detected cores:    4
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_sfd2d_oct
> _______________________________________________
> Pytables-users mailing list
> Pytables-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pytables-users
>
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to