Diagnosing dictionaries
Project description
yf
Diagnosing dictionaries
To install: pip install yf
Overview
The yf package provides a suite of tools designed to assist in the diagnosis and inspection of dictionaries, particularly useful for debugging and data validation in Python applications. It includes functions for printing dictionary key paths, validating dictionary contents against specified criteria, comparing dictionaries, and generating example dictionaries from a list of dictionaries.
Features
Key Path Printing
print_key_paths(d): Prints all key paths in a dictionary.print_key_paths_and_val_peep(d, n_characters_in_val_peep=15): Prints key paths along with a preview of their values, truncated to a specified number of characters.
Dictionary Validation
validate_kwargs(kwargs_to_validate, validation_dict, validation_funs=base_validation_funs, all_kwargs_should_be_in_validation_dict=False, ignore_misunderstood_validation_instructions=False): Validates a dictionary of keyword arguments (kwargs_to_validate) against a set of rules defined invalidation_dictusing the functions specified invalidation_funs.
Dictionary Comparison
are_equal_on_common_keys(dict1, dict2): Checks if two dictionaries are equal based on the keys they both share.first_difference_on_common_keys(dict1, dict2, key_path_so_far=None): Finds the first key path where two dictionaries differ.
Dictionary Analysis
json_size_of_fields(d): Returns a dictionary where the values are the sizes of the JSON string representations of the corresponding values in the input dictionary.example_dict_from_dict_list(dict_list, recursive=False): Generates an example dictionary that includes at least one occurrence of each key found in a list of dictionaries.dict_of_types_of_dict_values(x, recursive=False): Returns a dictionary describing the types of the values in the input dictionary, optionally doing so recursively.
Usage Examples
Printing Key Paths
d = {'a': {'b': {'c': 1}}}
print_key_paths(d)
Validating Keyword Arguments
validation_rules = {
'age': {'be at least': 18},
'name': {'be a': str}
}
kwargs = {'age': 20, 'name': 'John'}
validate_kwargs(kwargs, validation_rules)
Comparing Dictionaries
dict1 = {'a': 1, 'b': 2}
dict2 = {'a': 1, 'b': 3}
are_equal_on_common_keys(dict1, dict2) # Returns False
first_difference_on_common_keys(dict1, dict2) # Returns ['b']
Analyzing Dictionary Content
d = {'name': 'Alice', 'data': [1, 2, 3]}
json_size_of_fields(d)
Generating Example Dictionary from List
dict_list = [{'a': 1, 'b': 2}, {'b': 3, 'c': 4}]
example_dict_from_dict_list(dict_list)
Function Documentation
Each function in the yf package is documented with Python docstrings, providing a detailed description of its purpose, parameters, return values, and usage examples. This documentation is accessible via the Python help system or by reading the source code directly.
Installation
To install the yf package, use the following pip command:
pip install yf
This package is a powerful tool for developers working with complex data structures in Python, providing robust functionalities for dictionary diagnostics and validation.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yf-0.0.5.tar.gz.
File metadata
- Download URL: yf-0.0.5.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ab9fc1307d660dbd89ecee84e34fe3e11a753d1a0e7d0aacc0c669dc9345f1d
|
|
| MD5 |
53c58b3fe6c897abf14f38f5bbbbc7c7
|
|
| BLAKE2b-256 |
358773d16029a12af3a2217d99c412a5d4e5692afb499c042f0e0b9f733415f1
|
File details
Details for the file yf-0.0.5-py3-none-any.whl.
File metadata
- Download URL: yf-0.0.5-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca035a62293b344e38f766f8897fd79948c98156ee97b2625aa4201ab3d30858
|
|
| MD5 |
01e287104e3aaa54fbde38e54914ce60
|
|
| BLAKE2b-256 |
c8957d641f1be09d16d36679ac9ed69ad551756a08391a000bbefbb89ba92a48
|