Type
Source¶
Bases: Enum
Type of the values stored in an Array or in a Table column.
A result outside the range of its type raises an error, never a wrong number. Prefer INT64 unless memory
matters. Each member below gives the rules of its type.
Added in version 0.1.0
Examples:
import numdaplot as ndp
small_counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.INT8)
large_counts = ndp.Array.from_list([1000, 2000])
(small_counts + large_counts).dtype
# <Type.INT64: 4>
small_counts.convert(ndp.ArrayConversion(dtype=ndp.Type.FLOAT32)).dtype
# <Type.FLOAT32: 9>
try:
small_counts + 300
except ndp.IntegerOverflowError as error:
print(error)
# The operation + gives values outside the range of INT8, from -128 to 127. Convert the values to INT64 first.
Attributes¶
INT8 = auto()
Source¶
Signed integer from -128 to 127, 1 byte per value. It follows the rules of INT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.INT8)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.INT8: 1>, <Type.INT64: 4>)
try:
counts + 300
except ndp.IntegerOverflowError as error:
print(error)
# The operation + gives values outside the range of INT8, from -128 to 127. Convert the values to INT64 first.
INT16 = auto()
Source¶
Signed integer from -32 768 to 32 767, 2 bytes per value. It follows the rules of INT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.INT16)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.INT16: 2>, <Type.INT64: 4>)
try:
counts + 40000
except ndp.IntegerOverflowError as error:
print(error)
# The operation + gives values outside the range of INT16, from -32768 to 32767. Convert the values to INT64 first.
INT32 = auto()
Source¶
Signed integer of about +/- 2 billion, 4 bytes per value. It follows the rules of INT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.INT32)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.INT32: 3>, <Type.INT64: 4>)
try:
counts + 3000000000
except ndp.IntegerOverflowError as error:
print(error)
# The operation + gives values outside the range of INT32, from -2147483648 to 2147483647.
# Convert the values to INT64 first.
INT64 = auto()
Source¶
Signed integer of about +/- 9.2 * 10**18, 8 bytes per value. Default integer type: Python integers become
INT64.
A Python integer keeps the type of the values, a Python decimal gives FLOAT64. Division, the statistics and the
math functions giving decimals give FLOAT64, Sum gives INT64, and Min, Max, Absolute and
Round keep the type. An Array of integers cannot hold missing values: a Table column can.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2])
counts.dtype
# <Type.INT64: 4>
(counts + 1).dtype, (counts + 1.5).dtype, (counts / 2).dtype
# (<Type.INT64: 4>, <Type.FLOAT64: 10>, <Type.FLOAT64: 10>)
counts.compute(ndp.Sum()).dtype, counts.compute(ndp.Mean()).dtype, counts.apply(ndp.SquareRoot()).dtype
# (<Type.INT64: 4>, <Type.FLOAT64: 10>, <Type.FLOAT64: 10>)
counts.compute(ndp.Max()).dtype
# <Type.INT64: 4>
try:
ndp.Array.from_list([1, None], dtype=ndp.Type.INT64)
except ndp.UnsupportedMissingError as error:
print(error)
# INT64 values cannot be missing in an Array. Remove them, or give dtype=ndp.Type.FLOAT64.
UINT8 = auto()
Source¶
Unsigned integer from 0 to 255, 1 byte per value. It follows the rules of INT64, and Sum gives UINT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.UINT8)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.UINT8: 5>, <Type.UINT64: 8>)
try:
counts - 5
except ndp.IntegerOverflowError as error:
print(error)
# The operation - gives values outside the range of UINT8, from 0 to 255. Convert the values to INT64 first.
UINT16 = auto()
Source¶
Unsigned integer from 0 to 65 535, 2 bytes per value. It follows the rules of INT64, and Sum gives
UINT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.UINT16)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.UINT16: 6>, <Type.UINT64: 8>)
try:
counts - 5
except ndp.IntegerOverflowError as error:
print(error)
# The operation - gives values outside the range of UINT16, from 0 to 65535. Convert the values to INT64 first.
UINT32 = auto()
Source¶
Unsigned integer from 0 to about 4 billion, 4 bytes per value. It follows the rules of INT64, and Sum gives
UINT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.UINT32)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.UINT32: 7>, <Type.UINT64: 8>)
try:
counts - 5
except ndp.IntegerOverflowError as error:
print(error)
# The operation - gives values outside the range of UINT32, from 0 to 4294967295. Convert the values to INT64 first.
UINT64 = auto()
Source¶
Unsigned integer from 0 to about 1.8 * 10**19, 8 bytes per value. It follows the rules of INT64, and Sum
gives UINT64.
Added in version 0.1.0
Examples:
import numdaplot as ndp
counts = ndp.Array.from_list([1, 2], dtype=ndp.Type.UINT64)
(counts + 1).dtype, counts.compute(ndp.Sum()).dtype
# (<Type.UINT64: 8>, <Type.UINT64: 8>)
try:
counts - 5
except ndp.IntegerOverflowError as error:
print(error)
# The operation - gives values outside the range of UINT64, from 0 to 18446744073709551615.
# Convert the values to FLOAT64 first, which keeps about 16 digits.
FLOAT32 = auto()
Source¶
Decimal number with about 7 significant digits, 4 bytes per value. It stays FLOAT32 in every calculation.
Added in version 0.1.0
Examples:
FLOAT64 = auto()
Source¶
Decimal number with about 16 significant digits, 8 bytes per value. Default decimal type: Python decimals become
FLOAT64.
Decimals combined with integers, division, and the statistics and math functions of integers giving decimals give
FLOAT64. A missing value is nan.
Added in version 0.1.0
Examples:
BOOL = auto()
Source¶
True or false. Sum counts the true values and Mean gives their share. An Array of booleans cannot hold
missing values: a Table column can.
Added in version 0.1.0
Examples:
import numdaplot as ndp
answers = ndp.Array.from_list([True, False, True, True])
answers.compute(ndp.Sum()).to_value(), answers.compute(ndp.Mean()).to_value()
# (3, 0.75)
try:
ndp.Array.from_list([True, None])
except ndp.UnsupportedMissingError as error:
print(error)
# BOOL values cannot be missing in an Array. Remove them.
TEXT = auto()
Source¶
Text of any length. Python texts become TEXT. A missing text is shown as nan, and given as None by
to_list.
Added in version 0.1.0
Examples:
CATEGORY = auto()
Source¶
Text taking a few repeated values, stored once per distinct value. Table columns only: Table.column gives
their values as TEXT, and ArrayConversion refuses it.
Added in version 0.1.0
Examples:
import numdaplot as ndp
cities = ndp.Array.from_list(["Paris", "Lyon", "Paris"])
prices = ndp.Array.from_list([120.0, 80.0, 150.0])
sales = ndp.Table.from_arrays({"city": cities, "price": prices})
categories = sales.convert(ndp.TableConversion(columns=["city"], dtype=ndp.Type.CATEGORY))
categories.column_types["city"], categories.column("city").dtype
# (<Type.CATEGORY: 13>, <Type.TEXT: 12>)
DATE = auto()
Source¶
DATETIME = auto()
Source¶
A day and a time, with or without time zone, from 1677 to 2262. Python datetimes become DATETIME. A missing
datetime is NaT.
Added in version 0.1.0
Examples:
DURATION = auto()
Source¶
A gap between two dates or datetimes, of about 292 years at most, before or after zero. Python durations
(timedelta) become DURATION. A missing duration is NaT.
Added in version 0.1.0
Examples:
TIME = auto()
Source¶
A time of day, from 00:00 to 23:59:59.999999, without date nor time zone. Stored as the time since midnight.
Python times of day become TIME, and a missing one is given as None by to_list.
Two times give a DURATION when subtracted, a duration moves a time within its day, and a time added to a
DATE gives a DATETIME. Its hour, minute and second are read with DatePart.
Added in version 0.1.0
Examples: