A package to compare variables irrespective of their datatype
Project description
Deep Compare
Deep Compare is a simple module that lets the user compare two variables irrespective of their datatype.
Installation
$ pip install deep-compare
Requirements
- Python3.7+
Usage
Install the Deep Compare package using the command
$ pip install deep-compare
You will be able to use the package after installation by importing it in your python file.
from deep_compare import CompareVariables
CompareVariables includes 11 methods
1. is_float(value)
returns True if the value is an integer or float, else returns False
a = '17.5'
is_float = CompareVariables.is_float(a)
print(is_float)
Output
>>> True
a = 'hi'
is_float = CompareVariables.is_float(a)
print(is_float)
Output
>>> False
2. is_date_time(value)
returns True if value is a date or date-time(if the input datatype is a string the date or datetime must be in iso time format and the python version used must be 3.7 or above) else returns False
a = '2020-12-12 10:45'
is_date_time = CompareVariables.is_date_time(a)
print(is_date_time)
Output
>>> True
a = '15th january 2020 '
is_date_time = CompareVariables.is_date_time(a)
print(is_date_time)
Output
>>> False
3. can_literal_eval(value)
returns True if value is a list, dict, tuple, set etc.
a = '[2,5,6]'
can_literal_eval = CompareVariables.can_literal_eval(a)
print(can_literal_eval)
Output
>>> True
4. is_complex(value):
returns True if value is a complex number else returns False
a = '3 + 5j'
is_complex = CompareVariables.is_complex(a)
print(is_complex)
Output
>>> True
a = '15th january 2020 '
is_complex = CompareVariables.is_complex(a)
print(is_complex)
Output
>>> False
5. compare(value1, value2)
returns True if the values are equal else returns False
a = 5
b = 5
output = CompareVariables.compare(a,b)
print(output)
Output
>>> True
a = 5
b = '5'
output = CompareVariables.compare(a,b)
print(output)
Output
>>> False
6. compare_date(value1, value2):
returns True if the two input date values(value can be iso time format string also) are equal else returns False
a = '2020-12-12 10:58'
b = '2020-12-12'
output = CompareVariables.compare_date(a,b)
print(output)
Output
>>> True
a = '2020-12-12 10:58'
b = '2020-10-12 10:58'
output = CompareVariables.compare_date(a,b)
print(output)
Output
>>> False
7. compare_datetime(value1, value2):
returns True if the input two input datetime values(value can be iso time format string also) are equal else returns False
from datetime import datetime
a = '2020-12-12 10:58'
b = datetime(2020,12,12,10,58)
output = CompareVariables.compare_datetime(a,b)
print(output)
Output
>>> True
a = '2020-12-12 10:58'
b = '2020-12-12 11:58'
output = CompareVariables.compare_datetime(a,b)
print(output)
Output
>>> False
8. datatype_check(value):
returns the input value in its correct datatype else returns False
a = '3 + 4j'
output = CompareVariables.datatype_check(a)
print(output)
Output
>>> 3+4j
9. compare_list_or_tuples_or_set(value1, value2):
returns True if the input values(list/tuple/set) are equal else returns False
a = '[1,2,3,44]'
b = '["1","2","3","44"]'
output = CompareVariables.compare_list_or_tuples_or_set(a,b)
print(output)
Output
>>> True
a = '[1,2,3,44]'
b = '["1","2","3"]'
output = CompareVariables.compare_list_or_tuples_or_set(a,b)
print(output)
Output
>>> False
10. compare_dicts(value1, value2):
returns True if the input values(dicts) are equal else returns False
a = '{"1":"2",3:5}'
b = {1:2,3:5}
output = CompareVariables.compare_dicts(a,b)
print(output)
Output
>>> True
a = '{"1":"2",3:5}'
b = {1:2,3:5,4:6}
output = CompareVariables.compare_dicts(a,b)
print(output)
Output
>>> False
11. deep_compare(value1, value2):
returns True if the values are equal irrespective of the input datatype else returns False
a = '{"1":"2",3:5}'
b = {1:2,3:5}
output = CompareVariables.deep_compare(a,b)
print(output)
Output
>>> True
a = '[1,2,3,44]'
b = '["1","2","3"]'
output = CompareVariables.deep_compare(a,b)
print(output)
Output
>>> False
when comparing two datetime objects(or datetime string object) if the user only wants to compare the dates they can pass an *arg in the deep_compare function as shown below:
a = datetime(2020,5,2,12,48)
b = datetime(2020,5,2,10,18)
output = CompareVariables.deep_compare(a,b,date_only = True)
print(output)
Output
>>> True
a = '2020-05-02 12:48'
b = '2020-05-02'
output = CompareVariables.deep_compare(a,b,date_only = True)
print(output)
Output
>>> True
Communication
If you find a bug, open an issue. If you have a feature request, open an issue. If you want to contribute, submit a pull request.
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
Hashes for deep_compare-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10a08dda41e1f9f6d6b074cd5e4082f314d76d1305effb60649a1aaba48d4105 |
|
MD5 | 0359a550c825416fefe77b80212a6a00 |
|
BLAKE2b-256 | 4c2a00aba9fe2e5fe3bc39dc2bfccb351977172f569f95c38637026888a8360f |