extends the capability of truthiness evaluation beyond the standard Python truthiness rules to handle pandas DataFrames/Series and NumPy Arrays
Project description
extends the capability of truthiness evaluation beyond the standard Python truthiness rules to handle pandas DataFrames/Series and NumPy Arrays
pip install istruthy
Tested against Windows 10 / Python 3.10 / Anaconda
Args:
x: A value of any type.
Returns:
bool: True if the value is truthy, False otherwise. If an exception occurs while evaluating `x`,
False is returned unless `x` is an empty sequence (e.g., an empty list, tuple, or string),
in which case True is returned.
# Example
import pandas as pd
import numpy as np
v_bool = False
v_none = None
v_0_0 = 0
v_0_1 = 0.0
v_0_2 = 0j
empty_list = []
empty_tuple = ()
empty_dict = {}
empty_string = ""
empty_byte = b""
empty_bytearray = bytearray(b"")
empty_set = set()
empty_np_array = np.array([])
if not v_bool:
print(f"1) {v_bool} is falsy")
if not is_truthy(v_bool):
print(f"2) {v_bool} is falsy")
else:
print(f"1) {v_bool} is truthy")
if is_truthy(v_bool):
print(f"2) {v_bool} is truthy")
if not v_none:
print(f"1) {v_none} is falsy")
if not is_truthy(v_none):
print(f"2) {v_none} is falsy")
else:
print(f"1) {v_none} is truthy")
if is_truthy(v_none):
print(f"2) {v_none} is truthy")
if not v_0_0:
print(f"1) {v_0_0} is falsy")
if not is_truthy(v_0_0):
print(f"2) {v_0_0} is falsy")
else:
print(f"1) {v_0_0} is truthy")
if is_truthy(v_0_0):
print(f"2) {v_0_0} is truthy")
if not v_0_1:
print(f"1) {v_0_1} is falsy")
if not is_truthy(v_0_1):
print(f"2) {v_0_1} is falsy")
else:
print(f"1) {v_0_1} is truthy")
if is_truthy(v_0_1):
print(f"2) {v_0_1} is truthy")
if not v_0_2:
print(f"1) {v_0_2} is falsy")
if not is_truthy(v_0_2):
print(f"2) {v_0_2} is falsy")
else:
print(f"1) {v_0_2} is truthy")
if is_truthy(v_0_2):
print(f"2) {v_0_2} is truthy")
if not empty_list:
print(f"1) {empty_list} is falsy")
if not is_truthy(empty_list):
print(f"2) {empty_list} is falsy")
else:
print(f"1) {empty_list} is truthy")
if is_truthy(empty_list):
print(f"2) {empty_list} is truthy")
if not empty_tuple:
print(f"1) {empty_tuple} is falsy")
if not is_truthy(empty_tuple):
print(f"2) {empty_tuple} is falsy")
else:
print(f"1) {empty_tuple} is truthy")
if is_truthy(empty_tuple):
print(f"2) {empty_tuple} is truthy")
if not empty_dict:
print(f"1) {empty_dict} is falsy")
if not is_truthy(empty_dict):
print(f"2) {empty_dict} is falsy")
else:
print(f"1) {empty_dict} is truthy")
if is_truthy(empty_dict):
print(f"2) {empty_dict} is truthy")
if not empty_string:
print(f"1) {empty_string} is falsy")
if not is_truthy(empty_string):
print(f"2) {empty_string} is falsy")
else:
print(f"1) {empty_string} is truthy")
if is_truthy(empty_string):
print(f"2) {empty_string} is truthy")
if not empty_byte:
print(f"1) {empty_byte} is falsy")
if not is_truthy(empty_byte):
print(f"2) {empty_byte} is falsy")
else:
print(f"1) {empty_byte} is truthy")
if is_truthy(empty_byte):
print(f"2) {empty_byte} is truthy")
if not empty_bytearray:
print(f"1) {empty_bytearray} is falsy")
if not is_truthy(empty_bytearray):
print(f"2) {empty_bytearray} is falsy")
else:
print(f"1) {empty_bytearray} is truthy")
if is_truthy(empty_bytearray):
print(f"2) {empty_bytearray} is truthy")
if not empty_set:
print(f"1) {empty_set} is falsy")
if not is_truthy(empty_set):
print(f"2) {empty_set} is falsy")
else:
print(f"1) {empty_set} is truthy")
if is_truthy(empty_set):
print(f"2) {empty_set} is truthy")
print("----------------")
try:
if not empty_np_array:
print(f"1) {empty_np_array} is falsy")
if not is_truthy(empty_np_array):
print(f"2) {empty_np_array} is falsy")
else:
print(f"1) {empty_np_array} is truthy")
if is_truthy(empty_np_array):
print(f"2) {empty_np_array} is truthy")
except Exception:
if not is_truthy(empty_np_array):
print(f"2) {empty_np_array} is falsy")
if is_truthy(empty_np_array):
print(f"2) {empty_np_array} is truthy")
empty_np_array = pd.DataFrame()
try:
if not empty_np_array:
print(f"1) {empty_np_array} is falsy")
if not is_truthy(empty_np_array):
print(f"2) {empty_np_array} is falsy")
else:
print(f"1) {empty_np_array} is truthy")
if is_truthy(empty_np_array):
print(f"2) {empty_np_array} is truthy")
except Exception as fe:
print(fe)
if not is_truthy(empty_np_array):
print(f"2) {empty_np_array} is falsy")
if is_truthy(empty_np_array):
print(f"2) {empty_np_array} is truthy")
1) False is falsy
2) False is falsy
1) None is falsy
2) None is falsy
1) 0 is falsy
2) 0 is falsy
1) 0.0 is falsy
2) 0.0 is falsy
1) 0j is falsy
2) 0j is falsy
1) [] is falsy
2) [] is falsy
1) () is falsy
2) () is falsy
1) {} is falsy
2) {} is falsy
1) is falsy
2) is falsy
1) b'' is falsy
2) b'' is falsy
1) bytearray(b'') is falsy
2) bytearray(b'') is falsy
1) set() is falsy
2) set() is falsy
----------------
1) [] is falsy
2) [] is falsy
The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
2) Empty DataFrame
Columns: []
Index: [] is falsy
C:\ProgramData\anaconda3\envs\dfdir\istruthy.py:149: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if not empty_np_array:
C:\ProgramData\anaconda3\envs\dfdir\istruthy.py:24: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if x:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
istruthy-0.12.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file istruthy-0.12.tar.gz
.
File metadata
- Download URL: istruthy-0.12.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f422718e13b4dd1140e62ab8223938e9b5da9ae14ea577c881cb47a15fb16210 |
|
MD5 | 74e804a438a55a62c5f378de7cac59ca |
|
BLAKE2b-256 | 1916c9419f52bda4c4fec8956bf231b1310128b24bf82f0b1c6742222b3d85ed |
File details
Details for the file istruthy-0.12-py3-none-any.whl
.
File metadata
- Download URL: istruthy-0.12-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5068ae626069831c1dc11e6f7e0c6796e5da820b9d704120382fa29db1f22e07 |
|
MD5 | 83096737083b2d5beb8af837113239fe |
|
BLAKE2b-256 | a4d4c77c203b604d002d86547b045651f41172265ede1cae4037b6a272a18411 |