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

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2022-01-14
dita:mapPath
bol1585763678431.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
B700-4006
lifecycle
previous
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: []