istruthy


Nameistruthy JSON
Version 0.12 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/istruthy
Summaryextends the capability of truthiness evaluation beyond the standard Python truthiness rules to handle pandas DataFrames/Series and NumPy Arrays
upload_time2023-06-29 20:29:35
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords numpy pandas truthy falsy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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
```python

    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:


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/istruthy",
    "name": "istruthy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "numpy,pandas,truthy,falsy",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/19/16/c9419f52bda4c4fec8956bf231b1310128b24bf82f0b1c6742222b3d85ed/istruthy-0.12.tar.gz",
    "platform": null,
    "description": "\r\n# extends the capability of truthiness evaluation beyond the standard Python truthiness rules to handle pandas DataFrames/Series and NumPy Arrays\r\n\r\n## pip install istruthy\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n```python\r\n\r\n    Args:\r\n        x: A value of any type.\r\n\r\n    Returns:\r\n        bool: True if the value is truthy, False otherwise. If an exception occurs while evaluating `x`,\r\n              False is returned unless `x` is an empty sequence (e.g., an empty list, tuple, or string),\r\n              in which case True is returned.\r\n\r\n\r\n\r\n# Example\r\nimport pandas as pd\r\nimport numpy as np\r\n\r\nv_bool = False\r\nv_none = None\r\nv_0_0 = 0\r\nv_0_1 = 0.0\r\nv_0_2 = 0j\r\nempty_list = []\r\nempty_tuple = ()\r\nempty_dict = {}\r\nempty_string = \"\"\r\nempty_byte = b\"\"\r\nempty_bytearray = bytearray(b\"\")\r\nempty_set = set()\r\nempty_np_array = np.array([])\r\n\r\nif not v_bool:\r\n    print(f\"1) {v_bool} is falsy\")\r\n    if not is_truthy(v_bool):\r\n        print(f\"2) {v_bool} is falsy\")\r\nelse:\r\n    print(f\"1) {v_bool} is truthy\")\r\n    if is_truthy(v_bool):\r\n        print(f\"2) {v_bool} is truthy\")\r\nif not v_none:\r\n    print(f\"1) {v_none} is falsy\")\r\n    if not is_truthy(v_none):\r\n        print(f\"2) {v_none} is falsy\")\r\nelse:\r\n    print(f\"1) {v_none} is truthy\")\r\n    if is_truthy(v_none):\r\n        print(f\"2) {v_none} is truthy\")\r\nif not v_0_0:\r\n    print(f\"1) {v_0_0} is falsy\")\r\n    if not is_truthy(v_0_0):\r\n        print(f\"2) {v_0_0} is falsy\")\r\nelse:\r\n    print(f\"1) {v_0_0} is truthy\")\r\n    if is_truthy(v_0_0):\r\n        print(f\"2) {v_0_0} is truthy\")\r\nif not v_0_1:\r\n    print(f\"1) {v_0_1} is falsy\")\r\n    if not is_truthy(v_0_1):\r\n        print(f\"2) {v_0_1} is falsy\")\r\nelse:\r\n    print(f\"1) {v_0_1} is truthy\")\r\n    if is_truthy(v_0_1):\r\n        print(f\"2) {v_0_1} is truthy\")\r\nif not v_0_2:\r\n    print(f\"1) {v_0_2} is falsy\")\r\n    if not is_truthy(v_0_2):\r\n        print(f\"2) {v_0_2} is falsy\")\r\nelse:\r\n    print(f\"1) {v_0_2} is truthy\")\r\n    if is_truthy(v_0_2):\r\n        print(f\"2) {v_0_2} is truthy\")\r\nif not empty_list:\r\n    print(f\"1) {empty_list} is falsy\")\r\n    if not is_truthy(empty_list):\r\n        print(f\"2) {empty_list} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_list} is truthy\")\r\n    if is_truthy(empty_list):\r\n        print(f\"2) {empty_list} is truthy\")\r\nif not empty_tuple:\r\n    print(f\"1) {empty_tuple} is falsy\")\r\n    if not is_truthy(empty_tuple):\r\n        print(f\"2) {empty_tuple} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_tuple} is truthy\")\r\n    if is_truthy(empty_tuple):\r\n        print(f\"2) {empty_tuple} is truthy\")\r\nif not empty_dict:\r\n    print(f\"1) {empty_dict} is falsy\")\r\n    if not is_truthy(empty_dict):\r\n        print(f\"2) {empty_dict} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_dict} is truthy\")\r\n    if is_truthy(empty_dict):\r\n        print(f\"2) {empty_dict} is truthy\")\r\nif not empty_string:\r\n    print(f\"1) {empty_string} is falsy\")\r\n    if not is_truthy(empty_string):\r\n        print(f\"2) {empty_string} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_string} is truthy\")\r\n    if is_truthy(empty_string):\r\n        print(f\"2) {empty_string} is truthy\")\r\nif not empty_byte:\r\n    print(f\"1) {empty_byte} is falsy\")\r\n    if not is_truthy(empty_byte):\r\n        print(f\"2) {empty_byte} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_byte} is truthy\")\r\n    if is_truthy(empty_byte):\r\n        print(f\"2) {empty_byte} is truthy\")\r\nif not empty_bytearray:\r\n    print(f\"1) {empty_bytearray} is falsy\")\r\n    if not is_truthy(empty_bytearray):\r\n        print(f\"2) {empty_bytearray} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_bytearray} is truthy\")\r\n    if is_truthy(empty_bytearray):\r\n        print(f\"2) {empty_bytearray} is truthy\")\r\nif not empty_set:\r\n    print(f\"1) {empty_set} is falsy\")\r\n    if not is_truthy(empty_set):\r\n        print(f\"2) {empty_set} is falsy\")\r\nelse:\r\n    print(f\"1) {empty_set} is truthy\")\r\n    if is_truthy(empty_set):\r\n        print(f\"2) {empty_set} is truthy\")\r\nprint(\"----------------\")\r\ntry:\r\n    if not empty_np_array:\r\n        print(f\"1) {empty_np_array} is falsy\")\r\n        if not is_truthy(empty_np_array):\r\n            print(f\"2) {empty_np_array} is falsy\")\r\n    else:\r\n        print(f\"1) {empty_np_array} is truthy\")\r\n        if is_truthy(empty_np_array):\r\n            print(f\"2) {empty_np_array} is truthy\")\r\nexcept Exception:\r\n    if not is_truthy(empty_np_array):\r\n        print(f\"2) {empty_np_array} is falsy\")\r\n    if is_truthy(empty_np_array):\r\n        print(f\"2) {empty_np_array} is truthy\")\r\n\r\nempty_np_array = pd.DataFrame()\r\ntry:\r\n    if not empty_np_array:\r\n        print(f\"1) {empty_np_array} is falsy\")\r\n        if not is_truthy(empty_np_array):\r\n            print(f\"2) {empty_np_array} is falsy\")\r\n    else:\r\n        print(f\"1) {empty_np_array} is truthy\")\r\n        if is_truthy(empty_np_array):\r\n            print(f\"2) {empty_np_array} is truthy\")\r\nexcept Exception as fe:\r\n    print(fe)\r\n    if not is_truthy(empty_np_array):\r\n        print(f\"2) {empty_np_array} is falsy\")\r\n    if is_truthy(empty_np_array):\r\n        print(f\"2) {empty_np_array} is truthy\")\r\n\r\n\r\n\r\n\r\n1) False is falsy\r\n2) False is falsy\r\n1) None is falsy\r\n2) None is falsy\r\n1) 0 is falsy\r\n2) 0 is falsy\r\n1) 0.0 is falsy\r\n2) 0.0 is falsy\r\n1) 0j is falsy\r\n2) 0j is falsy\r\n1) [] is falsy\r\n2) [] is falsy\r\n1) () is falsy\r\n2) () is falsy\r\n1) {} is falsy\r\n2) {} is falsy\r\n1)  is falsy\r\n2)  is falsy\r\n1) b'' is falsy\r\n2) b'' is falsy\r\n1) bytearray(b'') is falsy\r\n2) bytearray(b'') is falsy\r\n1) set() is falsy\r\n2) set() is falsy\r\n----------------\r\n1) [] is falsy\r\n2) [] is falsy\r\nThe truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().\r\n2) Empty DataFrame\r\nColumns: []\r\nIndex: [] is falsy\r\nC:\\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.\r\n  if not empty_np_array:\r\nC:\\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.\r\n  if x:\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "extends the capability of truthiness evaluation beyond the standard Python truthiness rules to handle pandas DataFrames/Series and NumPy Arrays",
    "version": "0.12",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/istruthy"
    },
    "split_keywords": [
        "numpy",
        "pandas",
        "truthy",
        "falsy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4d4c77c203b604d002d86547b045651f41172265ede1cae4037b6a272a18411",
                "md5": "83096737083b2d5beb8af837113239fe",
                "sha256": "5068ae626069831c1dc11e6f7e0c6796e5da820b9d704120382fa29db1f22e07"
            },
            "downloads": -1,
            "filename": "istruthy-0.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "83096737083b2d5beb8af837113239fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5612,
            "upload_time": "2023-06-29T20:29:34",
            "upload_time_iso_8601": "2023-06-29T20:29:34.288365Z",
            "url": "https://files.pythonhosted.org/packages/a4/d4/c77c203b604d002d86547b045651f41172265ede1cae4037b6a272a18411/istruthy-0.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1916c9419f52bda4c4fec8956bf231b1310128b24bf82f0b1c6742222b3d85ed",
                "md5": "74e804a438a55a62c5f378de7cac59ca",
                "sha256": "f422718e13b4dd1140e62ab8223938e9b5da9ae14ea577c881cb47a15fb16210"
            },
            "downloads": -1,
            "filename": "istruthy-0.12.tar.gz",
            "has_sig": false,
            "md5_digest": "74e804a438a55a62c5f378de7cac59ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4411,
            "upload_time": "2023-06-29T20:29:35",
            "upload_time_iso_8601": "2023-06-29T20:29:35.957204Z",
            "url": "https://files.pythonhosted.org/packages/19/16/c9419f52bda4c4fec8956bf231b1310128b24bf82f0b1c6742222b3d85ed/istruthy-0.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-29 20:29:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "istruthy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "istruthy"
}
        
Elapsed time: 0.12819s