String Comparisons may be Case Insensitive | Teradata Python Package - String Comparisons may be Case Insensitive - 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

Comparing string literals when filtering with the teradataml DataFrame is not necessarily case sensitive.

All character data, except for CLOBs, accessed in the execution of a Teradata SQL statement has an attribute of CASESPECIFIC or NOT CASESPECIFIC, either by default or by explicit designation. Character string comparisons use this attribute to determine whether the comparison is case blind or case specific. Case specificity does not apply to CLOBs.

For more information, see the Character String Comparisons section in the Teradata Vantage™ - SQL Functions, Expressions, and Predicates, B035-1145.

For example:

>>> df.head(5)
               SepalLength  SepalWidth  PetalLength  PetalWidth         Name
                                                                
2                      4.7         3.2          1.3         0.2  Iris-setosa
4                      5.0         3.6          1.4         0.2  Iris-setosa
3                      4.6         3.1          1.5         0.2  Iris-setosa
1                      4.9         3.0          1.4         0.2  Iris-setosa
0                      5.1         3.5          1.4         0.2  Iris-setosa
 
>>> df[df['Name'] == 'iris-SETOSA'].head(5)
 
 
               SepalLength  SepalWidth  PetalLength  PetalWidth         Name
                                                                
2                      4.7         3.2          1.3         0.2  Iris-setosa
4                      5.0         3.6          1.4         0.2  Iris-setosa
3                      4.6         3.1          1.5         0.2  Iris-setosa
1                      4.9         3.0          1.4         0.2  Iris-setosa
0                      5.1         3.5          1.4         0.2  Iris-setosa

A workaround is to use the str.contains method with case = True.

>>> has_SETOSA = df['Name'].str.contains('iris-SETOSA', case = True)
>>> df[has_SETOSA == True]
 
Empty DataFrame
Columns: [SepalLength, SepalWidth, PetalLength, PetalWidth, Name]
Index: []