Git Product home page Git Product logo

Comments (12)

martindurant avatar martindurant commented on August 14, 2024

Do you know if float128 would be sufficient? The biggest int type in numpy (and therefore pandas, the target of fastparquet) is 64-bit. It seems to me like a bad idea to construct an object array of big-ints, although if that's your only option...
I can't follow your traceback, above, which only seems to be executing within ibis - perhaps it cannot understand numbers of such size either?

from fastparquet.

mrocklin avatar mrocklin commented on August 14, 2024

It is surprising and unfortunate that NumPy doesn't implement a Decimal DType. How does Parquet encode decimals? Perhaps we can encode and decode these specially to and from something?

@jreback, I take it that Pandas uses float for decimals?

from fastparquet.

jreback avatar jreback commented on August 14, 2024

we don't handle Decimal type very well either

from fastparquet.

mrocklin avatar mrocklin commented on August 14, 2024

In practice do people use floats or Python Decimal objects?

I guess this is one problem for which we probably wait for the underlying stack to improve (pandas 2.0 or some numpy evolution thing)

from fastparquet.

ephes avatar ephes commented on August 14, 2024

For me np.float32 would be sufficient, I won't be able to use bigger types anyway, since I want to create a huge feature matrix from the numbers. My problem is that I can't read the parquet files of my table. The int.frombytes call kind of works, but I wondered if there's a better way to convert an numpy array of dtype |S16 into a float array. The parquet files are created by an ibis table expression, but then I download the files directly via hdfs.get.

from fastparquet.

mrocklin avatar mrocklin commented on August 14, 2024

Is this helpful?

In [1]: import numpy as np

In [2]: x = np.array(['1.1', '2.2', '3.3'], dtype='S3')

In [3]: x.astype(np.float32)
Out[3]: array([ 1.10000002,  2.20000005,  3.29999995], dtype=float32)

from fastparquet.

ephes avatar ephes commented on August 14, 2024

Throws a value error. I don't know exactly how decimals are encoded in parquet, but the array of bytes can be decoded like this:

x = np.array([
    b'', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\\',
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\\',
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r{',
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19)'], dtype='|S32')
np.array([int.from_bytes(d, byteorder='big', signed=False) for d in x]) * 0.1

from fastparquet.

mrocklin avatar mrocklin commented on August 14, 2024

@martindurant would know more, but this might be helpful: https://github.com/Parquet/parquet-format/blob/master/LogicalTypes.md#decimal

The primitive type stores an unscaled integer value. For byte arrays, binary and fixed, the unscaled number must be encoded as two's complement using big-endian byte order (the most significant byte is the zeroth element). The scale stores the number of digits of that value that are to the right of the decimal point, and the precision stores the maximum number of digits supported in the unscaled value.

from fastparquet.

martindurant avatar martindurant commented on August 14, 2024

OK, now I follow you - what's missing is a conversion where the basic data is byte arrays rather than int or float. I can certainly add that.

from fastparquet.

martindurant avatar martindurant commented on August 14, 2024

Is there any chance you can send me an extract of your data, or something similar to it, so it can be included in a test? The correct values of the bytes array would do.
^ @ephes

from fastparquet.

ephes avatar ephes commented on August 14, 2024

@martindurant Oh, that would be cool :) - the correct result is array([ 0. , 777.2, 751.6, 345.1, 644.1])

from fastparquet.

martindurant avatar martindurant commented on August 14, 2024

@ephes , I am using your solution, because it works generally. However, it will be very slow for a large number of values. There are faster numpy alternatives that would work when the int size is <=8bytes. However, I would expect those to be stored as actual integers rather than byte-strings, so I am not implementing it until necessary. Note that in your case, the values are 32-byte strings (although it says 16 in the schema element), but 2-byte integers would have done. Perhaps there are options in the software that generated them (ibis?) that can produce the more useful int type representation.

from fastparquet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.