Package: istruthy
extends the capability of truthiness evaluation beyond the standard Python truthiness rules to handle pandas DataFrames/Series and NumPy Arrayspip install istruthyTested against Windows 10 / Python 3.10 / AnacondaArgs:x:Avalueofanytype.Returns:bool:Trueifthevalueistruthy,Falseotherwise.Ifanexceptionoccurswhileevaluating`x`,Falseisreturnedunless`x`isanemptysequence(e.g.,anemptylist,tuple,orstring),inwhichcaseTrueisreturned.# Exampleimportpandasaspdimportnumpyasnpv_bool=Falsev_none=Nonev_0_0=0v_0_1=0.0v_0_2=0jempty_list=[]empty_tuple=()empty_dict={}empty_string=""empty_byte=b""empty_bytearray=bytearray(b"")empty_set=set()empty_np_array=np.array([])ifnotv_bool:print(f"1){v_bool}is falsy")ifnotis_truthy(v_bool):print(f"2){v_bool}is falsy")else:print(f"1){v_bool}is truthy")ifis_truthy(v_bool):print(f"2){v_bool}is truthy")ifnotv_none:print(f"1){v_none}is falsy")ifnotis_truthy(v_none):print(f"2){v_none}is falsy")else:print(f"1){v_none}is truthy")ifis_truthy(v_none):print(f"2){v_none}is truthy")ifnotv_0_0:print(f"1){v_0_0}is falsy")ifnotis_truthy(v_0_0):print(f"2){v_0_0}is falsy")else:print(f"1){v_0_0}is truthy")ifis_truthy(v_0_0):print(f"2){v_0_0}is truthy")ifnotv_0_1:print(f"1){v_0_1}is falsy")ifnotis_truthy(v_0_1):print(f"2){v_0_1}is falsy")else:print(f"1){v_0_1}is truthy")ifis_truthy(v_0_1):print(f"2){v_0_1}is truthy")ifnotv_0_2:print(f"1){v_0_2}is falsy")ifnotis_truthy(v_0_2):print(f"2){v_0_2}is falsy")else:print(f"1){v_0_2}is truthy")ifis_truthy(v_0_2):print(f"2){v_0_2}is truthy")ifnotempty_list:print(f"1){empty_list}is falsy")ifnotis_truthy(empty_list):print(f"2){empty_list}is falsy")else:print(f"1){empty_list}is truthy")ifis_truthy(empty_list):print(f"2){empty_list}is truthy")ifnotempty_tuple:print(f"1){empty_tuple}is falsy")ifnotis_truthy(empty_tuple):print(f"2){empty_tuple}is falsy")else:print(f"1){empty_tuple}is truthy")ifis_truthy(empty_tuple):print(f"2){empty_tuple}is truthy")ifnotempty_dict:print(f"1){empty_dict}is falsy")ifnotis_truthy(empty_dict):print(f"2){empty_dict}is falsy")else:print(f"1){empty_dict}is truthy")ifis_truthy(empty_dict):print(f"2){empty_dict}is truthy")ifnotempty_string:print(f"1){empty_string}is falsy")ifnotis_truthy(empty_string):print(f"2){empty_string}is falsy")else:print(f"1){empty_string}is truthy")ifis_truthy(empty_string):print(f"2){empty_string}is truthy")ifnotempty_byte:print(f"1){empty_byte}is falsy")ifnotis_truthy(empty_byte):print(f"2){empty_byte}is falsy")else:print(f"1){empty_byte}is truthy")ifis_truthy(empty_byte):print(f"2){empty_byte}is truthy")ifnotempty_bytearray:print(f"1){empty_bytearray}is falsy")ifnotis_truthy(empty_bytearray):print(f"2){empty_bytearray}is falsy")else:print(f"1){empty_bytearray}is truthy")ifis_truthy(empty_bytearray):print(f"2){empty_bytearray}is truthy")ifnotempty_set:print(f"1){empty_set}is falsy")ifnotis_truthy(empty_set):print(f"2){empty_set}is falsy")else:print(f"1){empty_set}is truthy")ifis_truthy(empty_set):print(f"2){empty_set}is truthy")print("----------------")try:ifnotempty_np_array:print(f"1){empty_np_array}is falsy")ifnotis_truthy(empty_np_array):print(f"2){empty_np_array}is falsy")else:print(f"1){empty_np_array}is truthy")ifis_truthy(empty_np_array):print(f"2){empty_np_array}is truthy")exceptException:ifnotis_truthy(empty_np_array):print(f"2){empty_np_array}is falsy")ifis_truthy(empty_np_array):print(f"2){empty_np_array}is truthy")empty_np_array=pd.DataFrame()try:ifnotempty_np_array:print(f"1){empty_np_array}is falsy")ifnotis_truthy(empty_np_array):print(f"2){empty_np_array}is falsy")else:print(f"1){empty_np_array}is truthy")ifis_truthy(empty_np_array):print(f"2){empty_np_array}is truthy")exceptExceptionasfe:print(fe)ifnotis_truthy(empty_np_array):print(f"2){empty_np_array}is falsy")ifis_truthy(empty_np_array):print(f"2){empty_np_array}is truthy")1)Falseisfalsy2)Falseisfalsy1)Noneisfalsy2)Noneisfalsy1)0isfalsy2)0isfalsy1)0.0isfalsy2)0.0isfalsy1)0jisfalsy2)0jisfalsy1)[]isfalsy2)[]isfalsy1)()isfalsy2)()isfalsy1){}isfalsy2){}isfalsy1)isfalsy2)isfalsy1)b''isfalsy2)b''isfalsy1)bytearray(b'')isfalsy2)bytearray(b'')isfalsy1)set()isfalsy2)set()isfalsy----------------1)[]isfalsy2)[]isfalsyThetruthvalueofaDataFrameisambiguous.Usea.empty,a.bool(),a.item(),a.any()ora.all().2)EmptyDataFrameColumns:[]Index:[]isfalsyC:\ProgramData\anaconda3\envs\dfdir\istruthy.py:149:DeprecationWarning:Thetruthvalueofanemptyarrayisambiguous.ReturningFalse,butinfuturethiswillresultinanerror.Use`array.size>0`tocheckthatanarrayisnotempty.ifnotempty_np_array:C:\ProgramData\anaconda3\envs\dfdir\istruthy.py:24:DeprecationWarning:Thetruthvalueofanemptyarrayisambiguous.ReturningFalse,butinfuturethiswillresultinanerror.Use`array.size>0`tocheckthatanarrayisnotempty.ifx: