Filtering with Boolean Column Requires a Comparison | Teradata Python Package - Filtering with Boolean Column Requires a Comparison - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-09
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage

The Analytics Database does not support the Boolean data type. So the values '0' and '1' are used instead. To be consistent with pandas, '0' maps to 'False' and '1' maps to 'True'. This implies that the Boolean column in teradataml is numeric and behaves like a numeric column.

For example:
import teradataml
>>> df = df.assign(drop_columns = True,
                   Name= df.Name,
                   is_setosa = df.Name.str.contains('Setosa')
>>> df
              Name is_setosa
0  Iris-versicolor         0
1   Iris-virginica         0
2  Iris-versicolor         0
3   Iris-virginica         0
4   Iris-virginica         0
5      Iris-setosa         1
6   Iris-virginica         0
7  Iris-versicolor         0
8      Iris-setosa         1
9  Iris-versicolor         0
>>> df[df.is_setosa == 1]
          Name is_setosa
0  Iris-setosa         1
1  Iris-setosa         1
2  Iris-setosa         1
3  Iris-setosa         1
4  Iris-setosa         1
5  Iris-setosa         1
6  Iris-setosa         1
7  Iris-setosa         1
8  Iris-setosa         1
9  Iris-setosa         1

Using Boolean literals 'True' and 'False' when comparing is supported.

For example:

>>> df[df.is_setosa == True]
 
          Name is_setosa
0  Iris-setosa         1
1  Iris-setosa         1
2  Iris-setosa         1
3  Iris-setosa         1
4  Iris-setosa         1
5  Iris-setosa         1
6  Iris-setosa         1
7  Iris-setosa         1
8  Iris-setosa         1
9  Iris-setosa         1
>>> df[df.is_setosa == False]
 
              Name is_setosa
0  Iris-versicolor         0
1   Iris-virginica         0
2  Iris-versicolor         0
3   Iris-virginica         0
4   Iris-virginica         0
5   Iris-virginica         0
6  Iris-versicolor         0
7  Iris-versicolor         0
8   Iris-virginica         0
9  Iris-versicolor         0

A comparison operator is needed whenever using a Boolean column, or else an error is thrown.

For example:

>>> df[df.is_setosa]
 
 
OperationalError: [Version 16.20.0.38] [Session 1961] [Teradata Database] [Error 3707] Syntax error, expected something like a 'SUCCEEDS' keyword or a 'MEETS' keyword or a 'PRECEDES' keyword or an 'IN' keyword or a 'CONTAINS' keyword between the word 'is_setosa' and ';'.