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

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

The Advanced SQL Engine 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 ';'.