Type Conversions
A breakdown of each of the pykx.K types and their analogous numpy, pandas, and pyarrow types.
Cheat Sheet
| PyKX type | Python type | Numpy dtype | Pandas dtype | PyArrow type |
|---|---|---|---|---|
| List | list | object | object | Not Supported |
| Boolean | bool | bool | bool | Not Supported |
| GUID | uuid4 | uuid4 | uuid4 | uuid4 |
| Byte | int | uint8 | uint8 | uint8 |
| Short | int | int16 | int16 | int16 |
| Int | int | int32 | int32 | int32 |
| Long | int | int64 | int64 | int64 |
| Real | float | float32 | float32 | FloatArray |
| Float | float | float64 | float64 | DoubleArray |
| Char | bytes | |S1 | bytes8 | BinaryArray |
| Symbol | str | object | object | StringArray |
| Timestamp | datetime | datetime64[ns] | datetime64[ns] | TimestampArray |
| Month | date | datetime64[M] | datetime64[ns] | Not Supported |
| Date | date | datetime64[D] | datetime64[ns] | Date32Array |
| Timespan | timedelta | timedelta[ns] | timedelta64[ns] | DurationArray |
| Minute | timedelta | timedelta64[m] | timedelta64[ns] | Not Supported |
| Second | timedelta | timedelta64[s] | timedelta64[ns] | DurationArray |
| Time | timedelta | timedelta64[ms] | timedelta64[ns] | DurationArray |
| Dictionary | dict | Not Supported | Not Supported | Not Supported |
| Table | dict | records | DataFrame | Table |
pykx.List
Python
A python list of mixed types will be converted into a pykx.List.
>>> pykx.List([1, b'foo', 'bar', 4.5])
pykx.List(pykx.q('
1
"foo"
`bar
4.5
'))
Calling .py() on a pykx.List will return a generic python list object where each object is converted into its analogous python type.
>>> pykx.List([1, b'foo', 'bar', 4.5]).py()
[1, b'foo', 'bar', 4.5]
Numpy
A numpy list with dtype==object containing data of mixed types will be converted into a pykx.List
>>> pykx.List(np.array([1, b'foo', 'bar', 4.5], dtype=object))
pykx.List(pykx.q('
1
"foo"
`bar
4.5
'))
Calling .np() on a pykx.List object will return a numpy ndarray with dtype==object where each element has been converted into its closest analogous python type.
>>> pykx.List([1, b'foo', 'bar', 4.5]).np()
array([1, b'foo', 'bar', 4.5], dtype=object)
Pandas
Calling .pd() on a pykx.List object will return a pandas Series with dtype==object where each element has been converted into its closest analogous python type.
>>> pykx.List([1, b'foo', 'bar', 4.5]).pd()
0 1
1 b'foo'
2 bar
3 4.5
dtype: object
pykx.BooleanAtom
Python
The python bool type will be converted into a pykx.BooleanAtom.
>>> pykx.BooleanAtom(True)
pykx.BooleanAtom(pykx.q('1b'))
Calling .py() on a pykx.BooleanAtom will return a python bool object.
>>> pykx.BooleanAtom(True).py()
True
pykx.BooleanVector
Python
A list of python bool types will be converted into a pykx.BooleanVector.
>>> pykx.BooleanVector([True, False, True])
pykx.BooleanVector(pykx.q('101b'))
Calling .py() on a pykx.BooleanVector will return a list of python bool objects.
>>> pykx.BooleanVector([True, False, True]).py()
[True, False, True]
Numpy, Pandas, Pyarrow
Converting a pykx.BoolVector will result in an array of objects with the bool dtype, arrays of that dtype can also be converted into pykx.BoolVector objects.
pykx.GUIDAtom
Python
The python uuid4 type from the uuid library will be converted into a pykx.GUIDAtom.
>>> from uuid import uuid4
>>> pykx.GUIDAtom(uuid4())
pykx.GUIDAtom(pykx.q('012e8fb7-52c4-49e6-9b4e-93aa625ca3d7'))
Calling .py() on a pykx.GUIDAtom will return a python uuid4 object.
>>> pykx.GUIDAtom(uuid4()).py()
UUID('d16f9f3f-2a57-4dfd-818e-04c9c7a53584')
pykx.GUIDVector
Python
A list of python uuid4 types from the uuid library will be converted into a pykx.GUIDVector.
>>> pykx.GUIDVector([uuid4(), uuid4()])
pykx.GUIDVector(pykx.q('542ccbef-8aa1-4433-804a-7928172ec2d4 ff6f89fb-1aec-4073-821a-ce281ca6263e'))
Calling .py() on a pykx.GUIDVector will return a list of python uuid4 objects.
>>> pykx.GUIDVector([uuid4(), uuid4()]).py()
[UUID('a3b284fc-5f31-4ba2-b521-fa8b5c309e02'), UUID('95ee9044-3930-492c-96f2-e336110de023')]
Numpy, Pandas, PyArrow
Each of these will return an array of their respective object types around a list of uuid4 objects.
pykx.ByteAtom
Python
The python int type will be converted into a pykx.ByteAtom.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.ByteAtom(1.0)
pykx.ByteAtom(pykx.q('0x01'))
>>> pykx.ByteAtom(1.5)
pykx.ByteAtom(pykx.q('0x01'))
Calling .py() on a pykx.ByteAtom will return a python int object.
>>> pykx.ByteAtom(1.5).py()
1
pykx.ByteVector
Python
A list of python int types will be converted into a pykx.ByteVector.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.ByteVector([1, 2.5])
pykx.ByteVector(pykx.q('0x0102'))
Calling .py() on a pykx.ByteVector will return a list of python int objects.
>>> pykx.ByteVector([1, 2.5]).py()
[1, 2]
Numpy, Pandas, PyArrow
Converting a pykx.ByteVector will result in an array of objects with the uint8 dtype, arrays of that dtype can also be converted into pykx.ByteVector objects.
pykx.ShortAtom
Python
The python int type will be converted into a pykx.ShortAtom.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.ShortAtom(1)
pykx.ShortAtom(pykx.q('1h'))
>>> pykx.ShortAtom(1.5)
pykx.ShortAtom(pykx.q('1h'))
Calling .py() on a pykx.ShortAtom will return a python int object.
>>> pykx.ShortAtom(1.5).py()
1
pykx.ShortVector
Python
A list of python int types will be converted into a pykx.ShortVector.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.ShortVector([1, 2.5])
pykx.ShortVector(pykx.q('1 2h'))
Calling .py() on a pykx.ShortVector will return a list of python int objects.
>>> pykx.ShortVector([1, 2.5]).py()
[1, 2]
Numpy, Pandas, PyArrow
Converting a pykx.ShortVector will result in an array of objects with the int16 dtype, arrays of that dtype can also be converted into pykx.ShortVector objects.
pykx.IntAtom
Python
The python int type will be converted into a pykx.IntAtom.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.IntAtom(1)
pykx.IntAtom(pykx.q('1i'))
>>> pykx.IntAtom(1.5)
pykx.IntAtom(pykx.q('1i'))
Calling .py() on a pykx.IntAtom will return a python int object.
>>> pykx.IntAtom(1.5).py()
1
pykx.IntVector
Python
A list of python int types will be converted into a pykx.IntVector.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.IntVector([1, 2.5])
pykx.IntVector(pykx.q('1 2i'))
Calling .py() on a pykx.IntVector will return a list of python int objects.
>>> pykx.IntVector([1, 2.5]).py()
[1, 2]
Numpy, Pandas, PyArrow
Converting a pykx.IntVector will result in an array of objects with the int32 dtype, arrays of that dtype can also be converted into pykx.IntVector objects.
pykx.LongAtom
Python
The python int type will be converted into a pykx.LongAtom.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.LongAtom(1)
pykx.LongAtom(pykx.q('1'))
>>> pykx.LongAtom(1.5)
pykx.LongAtom(pykx.q('1'))
Calling .py() on a pykx.LongAtom will return a python int object.
>>> pykx.LongAtom(1.5).py()
1
pykx.LongVector
Python
A list of python int types will be converted into a pykx.LongVector.
Float types will also be converted but the decimal will be truncated away and no rounding done.
>>> pykx.LongVector([1, 2.5])
pykx.LongVector(pykx.q('1 2'))
Calling .py() on a pykx.LongVector will return a list of python int objects.
>>>> pykx.LongVector([1, 2.5]).py()
[1, 2]
Numpy, Pandas, PyArrow
Converting a pykx.LongVector will result in an array of objects with the int64 dtype, arrays of that dtype can also be converted into pykx.LongVector objects.
pykx.RealAtom
Python
The python float and int types will be converted into a pykx.RealAtom.
>>> pykx.RealAtom(2.5)
pykx.RealAtom(pykx.q('2.5e'))
Calling .py() on a pykx.RealAtom will return a python float object.
>>>> pykx.RealAtom(2.5).py()
2.5
pykx.RealVector
Python
A list of python int and float types will be converted into a pykx.RealVector.
>>> pykx.RealVector([1, 2.5])
pykx.RealVector(pykx.q('1 2.5e'))
Calling .py() on a pykx.RealVector will return a list of python float objects.
>>> pykx.RealVector([1, 2.5]).py()
[1.0, 2.5]
Numpy, Pandas
Converting a pykx.RealVector will result in an array of objects with the float32 dtype, arrays of that dtype can also be converted into pykx.RealVector objects.
PyArrow
This will return a PyArrow array with the FloatArray type.
pykx.FloatAtom
Python
The python float and int types will be converted into a pykx.FloatAtom.
>>> pykx.FloatAtom(2.5)
pykx.FloatAtom(pykx.q('2.5'))
Calling .py() on a pykx.FloatAtom will return a python float object.
>>>> pykx.FloatAtom(2.5).py()
2.5
pykx.FloatVector
Python
A list of python int and float types will be converted into a pykx.FloatVector.
>>> pykx.FloatVector([1, 2.5])
pykx.FloatVector(pykx.q('1 2.5'))
Calling .py() on a pykx.FloatVector will return a list of python float objects.
>>> pykx.FloatVector([1, 2.5]).py()
[1.0, 2.5]
Numpy, Pandas
Converting a pykx.FloatVector will result in an array of objects with the float64 dtype, arrays of that dtype can also be converted into pykx.FloatVector objects.
PyArrow
This will return a PyArrow array with the DoubleArray type.
pykx.CharAtom
Python
The python bytes type with length 1 will be converted into a pykx.CharAtom.
>>> pykx.CharAtom(b'a')
pykx.CharAtom(pykx.q('"a"'))
Calling .py() on a pykx.CharAtom will return a python bytes object.
>>> pykx.CharAtom(b'a').py()
b'a'
pykx.CharVector
Python
The python bytes type with length greater than 1 will be converted into a pykx.CharVector.
>>> pykx.CharVector(b'abc')
pykx.CharVector(pykx.q('"abc"'))
Calling .py() on a pykx.CharVector will return a python bytes object.
>>> pykx.CharVector(b'abc').py()
b'abc'
Numpy
Calling .np() on a pykx.CharVector will return a numpy ndarray with dtype '|S1'.
>>> pykx.CharVector(b'abc').np()
array([b'a', b'b', b'c'], dtype='|S1')
Converting a ndarray of this dtype will create a pykx.CharVector.
>>> pykx.CharVector(np.array([b'a', b'b', b'c'], dtype='|S1'))
pykx.CharVector(pykx.q('"abc"'))
Pandas
Calling .pd() on a pykx.CharVector will return a pandas Series with dtype bytes8.
>>> pykx.CharVector(b'abc').pd()
0 b'a'
1 b'b'
2 b'c'
dtype: bytes8
Converting a Series of this dtype will create a pykx.CharVector.
>>> pykx.CharVector(pd.Series([b'a', b'b', b'c'], dtype=bytes))
pykx.CharVector(pykx.q('"abc"'))
PyArrow
Calling .pa() on a pykx.CharVector will return a pyarrow BinaryArray.
<pyarrow.lib.BinaryArray object at 0x7f44cc099c00>
[
61,
62,
63
]
pykx.SymbolAtom
Python
The python string type will be converted into a pykx.SymbolAtom.
>>> pykx.toq('symbol')
pykx.SymbolAtom(pykx.q('`symbol'))
Calling .py() on a pykx.SymbolAtom will return a python string object.
>>> pykx.toq('symbol').py()
'symbol'
pykx.SymbolVector
Python
A list of python string types will be converted into a pykx.SymbolVector.
>>> pykx.SymbolVector(['a', 'b', 'c'])
pykx.SymbolVector(pykx.q('`a`b`c'))
Calling .py() on a pykx.SymbolVector will return a list of python string objects.
>>> pykx.SymbolVector(['a', 'b', 'c']).py()
['a', 'b', 'c']
Numpy
Calling .np() on a pykx.SymbolVector will return a numpy ndarray of python strings with dtype object.
>>> pykx.SymbolVector(['a', 'b', 'c']).np()
array(['a', 'b', 'c'], dtype=object)
Converting a ndarray of dtype object will create a pykx.SymbolVector.
>>> pykx.SymbolVector(np.array(['a', 'b', 'c'], dtype=object))
pykx.SymbolVector(pykx.q('`a`b`c'))
Pandas
Calling .pd() on a pykx.SymbolVector will return a pandas Series with dtype object.
>>> pykx.SymbolVector(['a', 'b', 'c']).pd()
0 a
1 b
2 c
dtype: object
PyArrow
Calling .pa() on a pykx.SymbolVector will return a pyarrow StringArray.
>>> pykx.SymbolVector(['a', 'b', 'c']).pa()
<pyarrow.lib.StringArray object at 0x7f44cc323fa0>
[
"a",
"b",
"c"
]
pykx.TimestampAtom
Python
The python datetime type will be converted into a pykx.TimestampAtom.
>>> kx.TimestampAtom(datetime(2150, 10, 22, 20, 31, 15, 70713))
pykx.TimestampAtom(pykx.q('2150.10.22D20:31:15.070713000'))
Calling .py() on a pykx.TimestampAtom will return a python datetime object.
>>> kx.TimestampAtom(datetime(2150, 10, 22, 20, 31, 15, 70713)).py()
datetime.datetime(2150, 10, 22, 20, 31, 15, 70713)
pykx.TimestampVector
Python
A list of python datetime types will be converted into a pykx.TimestampVector.
>>> kx.TimestampVector([datetime(2150, 10, 22, 20, 31, 15, 70713), datetime(2050, 10, 22, 20, 31, 15, 70713)])
pykx.TimestampVector(pykx.q('2150.10.22D20:31:15.070713000 2050.10.22D20:31:15.070713000'))
Calling .py() on a pykx.TimestampVector will return a list of python datetime objects.
>>> kx.TimestampVector([datetime(2150, 10, 22, 20, 31, 15, 70713), datetime(2050, 10, 22, 20, 31, 15, 70713)]).py()
[datetime.datetime(2150, 10, 22, 20, 31, 15, 70713), datetime.datetime(2050, 10, 22, 20, 31, 15, 70713)]
Numpy
Calling .np() on a pykx.TimestampVector will return a numpy ndarray with dtype datetime64[ns].
>>> kx.TimestampVector([datetime(2150, 10, 22, 20, 31, 15, 70713), datetime(2050, 10, 22, 20, 31, 15, 70713)]).np()
array(['2150-10-22T20:31:15.070713000', '2050-10-22T20:31:15.070713000'],
dtype='datetime64[ns]')
Converting a ndarray of dtype datetime64[ns] will create a pykx.TimestampVector.
>>> kx.TimestampVector(np.array(['2150-10-22T20:31:15.070713000', '2050-10-22T20:31:15.070713000'], dtype='datetime64[ns]'))
pykx.TimestampVector(pykx.q('2150.10.22D20:31:15.070713000 2050.10.22D20:31:15.070713000'))
Pandas
Calling .pd() on a pykx.TimestampVector will return a pandas Series with dtype datetime64[ns].
>>> kx.TimestampVector([datetime(2150, 10, 22, 20, 31, 15, 70713), datetime(2050, 10, 22, 20, 31, 15, 70713)]).pd()
0 2150-10-22 20:31:15.070713
1 2050-10-22 20:31:15.070713
dtype: datetime64[ns]
PyArrow
Calling .pa() on a pykx.TimestampVector will return a pyarrow TimestampArray.
>>> kx.TimestampVector([datetime(2150, 10, 22, 20, 31, 15, 70713), datetime(2050, 10, 22, 20, 31, 15, 70713)]).pa()
<pyarrow.lib.TimestampArray object at 0x7f6428f0dde0>
[
2150-10-22 20:31:15.070713000,
2050-10-22 20:31:15.070713000
]
pykx.MonthAtom
Python
The python date type will be converted into a pykx.MonthAtom.
>>> from datetime import date
>>> kx.MonthAtom(date(1972, 5, 1))
pykx.MonthAtom(pykx.q('1972.05m'))
Calling .py() on a pykx.MonthAtom will return a python date object.
>>> kx.MonthAtom(date(1972, 5, 1)).py()
datetime.date(1972, 5, 1)
pykx.MonthVector
Python
A list of python date types will be converted into a pykx.MonthVector.
>>> kx.MonthVector([date(1972, 5, 1), date(1999, 5, 1)])
pykx.MonthVector(pykx.q('1972.05 1999.05m'))
Calling .py() on a pykx.MonthVector will return a list of python date objects.
>>> kx.MonthVector([date(1972, 5, 1), date(1999, 5, 1)]).py()
[datetime.date(1972, 5, 1), datetime.date(1999, 5, 1)]
Numpy
Calling .np() on a pykx.MonthVector will return a numpy ndarray with dtype datetime64[M].
>>> kx.MonthVector([date(1972, 5, 1), date(1999, 5, 1)]).np()
array(['1972-05', '1999-05'], dtype='datetime64[M]')
Converting a ndarray of dtype datetime64[M] will create a pykx.MonthVector.
>>> kx.MonthVector(np.array(['1972-05', '1999-05'], dtype='datetime64[M]'))
pykx.MonthVector(pykx.q('1972.05 1999.05m'))
Pandas
Calling .pd() on a pykx.MonthVector will return a pandas Series with dtype datetime64[ns].
>>> kx.MonthVector([date(1972, 5, 1), date(1999, 5, 1)]).pd()
0 1972-05-01
1 1999-05-01
dtype: datetime64[ns]
pykx.DateAtom
Python
The python date type will be converted into a pykx.DateAtom.
>>> kx.DateAtom(date(1972, 5, 31))
pykx.DateAtom(pykx.q('1972.05.31'))
Calling .py() on a pykx.DateAtom will return a python date object.
>>> kx.DateAtom(date(1972, 5, 31)).py()
datetime.date(1972, 5, 31)
pykx.DateVector
Python
A list of python date types will be converted into a pykx.DateVector.
>>> kx.DateVector([date(1972, 5, 1), date(1999, 5, 1)])
pykx.DateVector(pykx.q('1972.05.01 1999.05.01'))
Calling .py() on a pykx.DateVector will return a list of python date objects.
>>> kx.DateVector([date(1972, 5, 1), date(1999, 5, 1)]).py()
[datetime.date(1972, 5, 1), datetime.date(1999, 5, 1)]
Numpy
Calling .np() on a pykx.DateVector will return a numpy ndarray of python strings with dtype datetime64[D].
>>> kx.DateVector([date(1972, 5, 1), date(1999, 5, 1)]).np()
array(['1972-05-01', '1999-05-01'], dtype='datetime64[D]')
Converting a ndarray of dtype datetime64[D] will create a pykx.DateVector.
>>> kx.DateVector(np.array(['1972-05-01', '1999-05-01'], dtype='datetime64[D]'))
pykx.DateVector(pykx.q('1972.05.01 1999.05.01'))
Pandas
Calling .pd() on a pykx.DateVector will return a pandas Series with dtype datetime64[ns].
>>> kx.DateVector([date(1972, 5, 1), date(1999, 5, 1)]).pd()
0 1972-05-01
1 1999-05-01
dtype: datetime64[ns]
PyArrow
Calling .pa() on a pykx.DateVector will return a pyarrow Date32Array.
>>> kx.DateVector([date(1972, 5, 1), date(1999, 5, 1)]).pa()
<pyarrow.lib.Date32Array object at 0x7f6428f0de40>
[
1972-05-01,
1999-05-01
]
pykx.Datetime types
Python and Numpy
These types are deprecated and can only be accessed using the raw key word argument.
Converting these types to python will return a float object or a float64 object in numpy's case.
>>> kx.q('0001.02.03T04:05:06.007, 0001.02.03T04:05:06.007').py(raw=True)
[-730085.8297915857, -730085.8297915857]
>>> kx.q('0001.02.03T04:05:06.007, 0001.02.03T04:05:06.007').np(raw=True)
array([-730085.82979159, -730085.82979159])
>>> kx.q('0001.02.03T04:05:06.007, 0001.02.03T04:05:06.007').np(raw=True).dtype
dtype('float64')
pykx.TimespanAtom
Python
The python timedelta type will be converted into a pykx.TimespanAtom.
>>> from datetime import timedelta
>>> kx.TimespanAtom(timedelta(days=43938, seconds=68851, microseconds=664551))
pykx.TimespanAtom(pykx.q('43938D19:07:31.664551000'))
Calling .py() on a pykx.TimespanAtom will return a python timedelta object.
>>> kx.TimespanAtom(timedelta(days=43938, seconds=68851, microseconds=664551)).py()
datetime.timedelta(days=43938, seconds=68851, microseconds=664551)
pykx.TimespanVector
Python
A list of python timedelta types will be converted into a pykx.TimespanVector.
>>> kx.TimespanVector([timedelta(days=43938, seconds=68851, microseconds=664551), timedelta(days=43938, seconds=68851, microseconds=664551)])
pykx.TimespanVector(pykx.q('43938D19:07:31.664551000 43938D19:07:31.664551000'))
Calling .py() on a pykx.TimespanVector will return a list of python timedelta objects.
>>> kx.TimespanVector([timedelta(days=43938, seconds=68851, microseconds=664551), timedelta(days=43938, seconds=68851, microseconds=664551)]).py()
[datetime.timedelta(days=43938, seconds=68851, microseconds=664551), datetime.timedelta(days=43938, seconds=68851, microseconds=664551)]
Numpy
Calling .np() on a pykx.TimespanVector will return a numpy ndarray of python strings with dtype timedelta64[ns].
>>> kx.TimespanVector([timedelta(days=43938, seconds=68851, microseconds=664551), timedelta(days=43938, seconds=68851, microseconds=664551)]).np()
array([3796312051664551000, 3796312051664551000], dtype='timedelta64[ns]')
Converting a ndarray of dtype datetime64[ns] will create a pykx.TimespanVector.
>>> kx.TimespanVector(np.array([3796312051664551000, 3796312051664551000], dtype='timedelta64[ns]'))
pykx.TimespanVector(pykx.q('43938D19:07:31.664551000 43938D19:07:31.664551000'))
Pandas
Calling .pd() on a pykx.TimespanVector will return a pandas Series with dtype timedelta64[ns].
>>> kx.TimespanVector([timedelta(days=43938, seconds=68851, microseconds=664551), timedelta(days=43938, seconds=68851, microseconds=664551)]).pd()
0 43938 days 19:07:31.664551
1 43938 days 19:07:31.664551
dtype: timedelta64[ns]
PyArrow
Calling .pa() on a pykx.TimespanVector will return a pyarrow DurationArray.
>>> kx.TimespanVector([timedelta(days=43938, seconds=68851, microseconds=664551), timedelta(days=43938, seconds=68851, microseconds=664551)]).pa()
<pyarrow.lib.DurationArray object at 0x7f6428f0dea0>
[
3796312051664551000,
3796312051664551000
]
pykx.MinuteAtom
Python
The python timedelta type will be converted into a pykx.MinuteAtom.
>>> kx.MinuteAtom(timedelta(minutes=216))
pykx.MinuteAtom(pykx.q('03:36'))
Calling .py() on a pykx.MinuteAtom will return a python timedelta object.
>>> kx.MinuteAtom(timedelta(minutes=216)).py()
datetime.timedelta(seconds=12960)
pykx.MinuteVector
Python
A list of python timedelta types will be converted into a pykx.MinuteVector.
>>> kx.MinuteVector([timedelta(minutes=216), timedelta(minutes=67)])
pykx.MinuteVector(pykx.q('03:36 01:07'))
Calling .py() on a pykx.MinuteVector will return a list of python timedelta objects.
>>> kx.MinuteVector([timedelta(minutes=216), timedelta(minutes=67)]).py()
[datetime.timedelta(seconds=12960), datetime.timedelta(seconds=4020)]
Numpy
Calling .np() on a pykx.MinuteVector will return a numpy ndarray of python strings with dtype timedelta64[m].
>>> kx.MinuteVector([timedelta(minutes=216), timedelta(minutes=67)]).np()
array([216, 67], dtype='timedelta64[m]')
Converting a ndarray of dtype timedelta64[m] will create a pykx.MinuteVector.
>>> kx.MinuteVector(np.array([216, 67], dtype='timedelta64[m]'))
pykx.MinuteVector(pykx.q('03:36 01:07'))
Pandas
Calling .pd() on a pykx.MinuteVector will return a pandas Series with dtype timedelta64[ns].
>>> kx.MinuteVector([timedelta(minutes=216), timedelta(minutes=67)]).pd()
0 0 days 03:36:00
1 0 days 01:07:00
dtype: timedelta64[ns]
pykx.SecondAtom
Python
The python timedelta type will be converted into a pykx.SecondAtom.
>>> kx.SecondAtom(timedelta(seconds=13019))
pykx.SecondAtom(pykx.q('03:36:59'))
Calling .py() on a pykx.SecondAtom will return a python timedelta object.
>>> kx.SecondAtom(timedelta(seconds=13019)).py()
datetime.timedelta(seconds=13019)
pykx.SecondVector
Python
A list of python timedelta types will be converted into a pykx.SecondVector.
>>> kx.SecondVector([timedelta(seconds=13019), timedelta(seconds=1019)])
pykx.SecondVector(pykx.q('03:36:59 00:16:59'))
Calling .py() on a pykx.SecondVector will return a list of python timedelta objects.
>>> kx.SecondVector([timedelta(seconds=13019), timedelta(seconds=1019)]).py()
[datetime.timedelta(seconds=13019), datetime.timedelta(seconds=1019)]
Numpy
Calling .np() on a pykx.SecondVector will return a numpy ndarray of python strings with dtype timedelta64[s].
>>> kx.SecondVector([timedelta(seconds=13019), timedelta(seconds=1019)]).np()
array([13019, 1019], dtype='timedelta64[s]')
Converting a ndarray of dtype timedelta64[s] will create a pykx.SecondVector.
>>> kx.SecondVector(np.array([13019, 1019], dtype='timedelta64[s]'))
pykx.SecondVector(pykx.q('03:36:59 00:16:59'))
Pandas
Calling .pd() on a pykx.SecondVector will return a pandas Series with dtype timedelta64[ns].
>>> kx.SecondVector([timedelta(seconds=13019), timedelta(seconds=1019)]).pd()
0 0 days 03:36:59
1 0 days 00:16:59
dtype: timedelta64[ns]
PyArrow
Calling .pa() on a pykx.SecondVector will return a pyarrow DurationArray.
>>> kx.SecondVector([timedelta(seconds=13019), timedelta(seconds=1019)]).pa()
<pyarrow.lib.DurationArray object at 0x7f6428f0e020>
[
13019,
1019
]
pykx.TimeAtom
Python
The python timedelta type will be converted into a pykx.TimeAtom.
>>> kx.TimeAtom(timedelta(seconds=59789, microseconds=214000))
pykx.TimeAtom(pykx.q('16:36:29.214'))
Calling .py() on a pykx.TimeAtom will return a python timedelta object.
>>> kx.TimeAtom(timedelta(seconds=59789, microseconds=214000)).py()
datetime.timedelta(seconds=59789, microseconds=214000)
pykx.TimeVector
Python
A list of python timedelta types will be converted into a pykx.TimeVector.
>>> kx.TimeVector([timedelta(seconds=59789, microseconds=214000), timedelta(seconds=23789, microseconds=214000)])
pykx.TimeVector(pykx.q('16:36:29.214 06:36:29.214'))
Calling .py() on a pykx.TimeVector will return a list of python timedelta objects.
>>> kx.TimeVector([timedelta(seconds=59789, microseconds=214000), timedelta(seconds=23789, microseconds=214000)]).py()
[datetime.timedelta(seconds=59789, microseconds=214000), datetime.timedelta(seconds=23789, microseconds=214000)]
Numpy
Calling .np() on a pykx.TimeVector will return a numpy ndarray of python strings with dtype timedelta64[ms].
>>> kx.TimeVector([timedelta(seconds=59789, microseconds=214000), timedelta(seconds=23789, microseconds=214000)]).np()
array([59789214, 23789214], dtype='timedelta64[ms]')
Converting a ndarray of dtype timedelta64[ms] will create a pykx.TimeVector.
>>> kx.TimeVector(np.array([59789214, 23789214], dtype='timedelta64[ms]'))
pykx.TimeVector(pykx.q('16:36:29.214 06:36:29.214'))
Pandas
Calling .pd() on a pykx.TimeVector will return a pandas Series with dtype timedelta64[ns].
>>> kx.TimeVector([timedelta(seconds=59789, microseconds=214000), timedelta(seconds=23789, microseconds=214000)]).pd()
0 0 days 16:36:29.214000
1 0 days 06:36:29.214000
dtype: timedelta64[ns]
PyArrow
Calling .pa() on a pykx.TimeVector will return a pyarrow DurationArray.
>>> kx.TimeVector([timedelta(seconds=59789, microseconds=214000), timedelta(seconds=23789, microseconds=214000)]).pa()
<pyarrow.lib.DurationArray object at 0x7f643021ff40>
[
59789214,
23789214
]
pykx.Dictionary
Python
A python dict type will be converted into a pykx.Dictionary.
>>> kx.Dictionary({'foo': b'bar', 'baz': 3.5, 'z': 'prime'})
pykx.Dictionary(pykx.q('
foo| "bar"
baz| 3.5
z | `prime
'))
Calling .py() on a pykx.Dictionary will return a python dict object.
>>> kx.Dictionary({'foo': b'bar', 'baz': 3.5, 'z': 'prime'}).py()
{'foo': b'bar', 'baz': 3.5, 'z': 'prime'}
pykx.Table
Python
Calling .py() on a pykx.Table will return a python dict object.
>>> kx.q('([] a: 10?10; b: 10?10)').py()
{'a': [5, 6, 4, 1, 3, 3, 7, 8, 2, 1], 'b': [8, 1, 7, 2, 4, 5, 4, 2, 7, 8]}
Numpy
Calling .np() on a pykx.Table will return a numpy record array of the rows of the table with each type converted to it closest analogous numpy type.
>>> kx.q('([] a: 10?10; b: 10?10)').np()
rec.array([(9, 9), (9, 7), (2, 6), (5, 6), (4, 4), (2, 7), (5, 8), (8, 4),
(7, 4), (9, 6)],
dtype=[('a', '<i8'), ('b', '<i8')])
Pandas
Calling .pd() on a pykx.Table will return a pandas DataFrame with each column being converted to its closest pandas dtype.
>>> kx.q('([] a: 10?10; b: 10?10)').pd()
a b
0 1 9
1 0 7
2 5 7
3 1 1
4 0 9
5 0 1
6 1 0
7 7 8
8 6 8
9 3 3
Converting a pandas DataFrame object will result in a pykx.Table object.
>>> kx.Table(pd.DataFrame({'a': [x for x in range(10)], 'b': [float(x) for x in range(10)]}))
pykx.Table(pykx.q('
a b
---
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
'))
PyArrow
Calling .pa() on a pykx.Table will return a pyarrow Table.
>>> kx.q('([] a: 10?10; b: 10?10)').pa()
pyarrow.Table
a: int64
b: int64
----
a: [[0,7,3,3,6,8,2,3,8,9]]
b: [[5,7,5,6,7,0,2,1,8,1]]
Converting a pyarow Table object will result in a pykx.Table object.
>>> kx.Table(pa.Table.from_arrays([[1, 2, 3, 4], [5, 6, 7, 8]], names=['a', 'b']))
pykx.Table(pykx.q('
a b
---
1 5
2 6
3 7
4 8
'))