Filtering with Boolean Series Needs a Comparison

Teradata® Python Package User Guide

brand
Teradata Vantage
prodname
Teradata Python Package
vrm_release
16.20
category
User Guide
featnum
B700-4006-098K

The SQL Engine does not support a boolean 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 Series 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 Series, 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 ';'.