Skip to content

How can I check if an array field contains a certain value OR the array field is null? #9757

Answered by cpcloud
chrispy-snps asked this question in Q&A
Discussion options

You must be logged in to vote

You're missing the () around the t.json_data["versions"] == None.

The | operator binds tighter than ==, so the parentheiszation (the way the Python interpreter sees it) of what you've written is actually

(t.json_data["versions"].cast("array<str>").contains("v1") | t.json_data["versions"]) == None

You'll need to parenthesize any binary operators in the specific way that you want to evaluate them when any of the bitwise operators (|, &, and ^) are in an expression.

In this case that'd be:

t.json_data["versions"].cast("array<str>").contains("v1") | (t.json_data["versions"] == None)

Running that in IPython:

In [14]: t.json_data["versions"].cast("array<str>").contains("v1") | (t.json_data["ver…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@chrispy-snps
Comment options

@cpcloud
Comment options

Answer selected by cpcloud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants