Kdb where not null?
Replace nulls
Replace nulls
Where x and y are conforming lists or dictionaries returns y with any nulls replaced by the corresponding item of x.
Integer x items are promoted when y is float or real.
When x and y are dictionaries, both null and missing values in y are filled with those from x.
Fill is an atomic function.
Domain and range:
Range: bcdefghijmnpstuvxz
^ Coalesce where x and y are keyed tables
Replace nulls with preceding non-nulls
Where x is a list, returns x with any null items replaced by their preceding non-null values, if any.
fills is a uniform function.
To back-fill, reverse the list and the result:
For a similar function on infinities, first replace them with nulls:
The keyword fills is defined as ^\, which fills forward, meaning that non-null items are filled over succeeding null items.
To fill initial nulls apply the derived function as a binary.
- SELECT column_names. FROM table_name. WHERE column_name IS NULL;
- SELECT column_names. FROM table_name. WHERE column_name IS NOT NULL;
- ExampleGet your own SQL Server. SELECT CustomerName, ContactName, Address. FROM Customers.
- Example. SELECT CustomerName, ContactName, Address. FROM Customers.
When the generic null is applied to another value, it is the Identity function.
Indexing with the generic null has the same effect.
Return a value unchanged
Where x is any value, returns x.
Applying multiple functions to the same data, with one of the operations as “do nothing”.
Identity can also be achieved via indexing.
and used in variants thereof for e.g. amends
When prefix notation is used, x does not have to be an applicable value.
Q does not have a dedicated null type. Instead :: is used to denote a generic null value. For example, functions that ‘return no value’, actually return ::.
When a unary function is called with no arguments, :: is passed in.
Since :: has a type for which no vector variant exists, it is useful to prevent a mixed list from being coerced into a vector when all items happen to be of the same type. (This is important when you need to preserve the ability to add non-conforming items later.)
PyKX and its management of nulls and infinities inherited from q operate differently in subtle ways from familiar libraries such as Numpy.
PyKX provides typed null and infinity values for most types. As shown in the q docs, nulls can be expressed as 0N followed by a type character (or no type character for long integer null), while infinities can be expressed as 0W followed by a type character (or no type character for a long integer infinity).
Datatypes in q designate a particular value in their numeric range as null, and another two as positive and negative infinity. Most other languages, such as Python, have no way to represent infinity for anything other than IEEE floating point numbers, and where typed nulls exist, they will not also be a value in the range of the datatype (save for floats, which can be NaN).
For example, the q null short integer 0Nh is stored as the value -32768 (i.e. the smallest possible signed 16 bit integer), and the q infinite short integer is stored as the value 32767 (i.e the largest possible signed 16 bit integer).
Due to the design of nulls and infinites in q, there are some technical considerations - detailed on this page - regarding converting nulls and infinities between Python and q in either direction.
The q function named null can be applied to most PyKX objects, and will return if the object is null by returning 1b, or if it contains nulls by returning a collection of booleans whose shape matches the object. Like with any function from the .q namespace, it can be accessed via the context interface: q.null).
pykx.Atom objects provide the properties is_null and is_inf. These are True if the atom is a null value for its type, or an infinite value (positive or negative) for its type, respectively, and False otherwise. is_inf is always False for types which do not have an infinite value in q, such as symbols.
Likewise, all pykx.Collection objects provide the properties has_nulls and has_infs. They are True if the collection has any nulls/infinities in it.
Some null values are unintuitive. For instance, the null value for a character in q is the space " ", the null value for a symbol is the empty symbol, and the null value for a GUID is 00000000-0000-0000-0000-000000000000. A char vector (i.e. q string) that has any spaces in it will have has_nulls set to True.
Vectors with the q types short, int, and long can be converted to Python in the following ways:
Real vectors use the standard NaN and inf values, and so are handled by q, Python, Numpy, Pandas, and PyArrow in the same way with no special handling.
Temporal vectors use NaT to represent null values in Numpy and Pandas, None to represent them in pure Python, and PyArrow represents null temporal values like it does for any other data type: by masking it out using the array metadata.
When converting a table from q to Python with one of the methods above, each column will be transformed as an independent vector as described above.
Wherever practical the conversions from q to Python are symmetric, so most of the conversions detailed in the section above work in reverse too. For instance, if you convert a Numpy masked array with dtype np.int32 to q, the masked values will be represented by int null (0Ni) in q.
By default, whenever PyKX converts a q vector to some Python representation (e.g. a Numpy array) it checks where the nulls (if any) are located. This requires operating on every element of the array, which can be rather expensive. If you know ahead of time that your q vector/table has no nulls in it, you can provide the keyword argument has_nulls=False to .py/.np/.pd/.pa. This will skip the null-check. If you set this keyword argument to false, but there are still nulls in the data, they will come through as the underlying values from q, e.g. -32768 for a short integer.
By default has_nulls is None. It can be set to True to always handle the data as if it contains nulls, regardless of whether it actually does. This can improve consistency in some cases, for instance by having all int vectors be converted to Numpy masked arrays instead of normal Numpy arrays when there are no nulls, and masked arrays when there are nulls.