[ase-users] ase-db question on booleans

John Kitchin jkitchin at andrew.cmu.edu
Fri Mar 3 14:35:06 CET 2017


I favor proper booleans. In Mongo for example, you cannot query a
boolean field with integers, you have to use booleans. e.g.

db.atoms.find({relaxed: 0}) will not find atoms with a relaxed field
that is equal to false.

this does work as a query though:

db.atoms.find({relaxed: false})


Ask Hjorth Larsen writes:

> Hi
>
> 2017-03-03 2:39 GMT+01:00 John Kitchin via ase-users
> <ase-users at listserv.fysik.dtu.dk>:
>> Hi all,
>>
>> In ase.db.core there is this function:
>>
>> def convert_str_to_int_float_or_str(value):
>>     """Safe eval()"""
>>     try:
>>         return int(value)
>>     except ValueError:
>>         try:
>>             value = float(value)
>>         except ValueError:
>>             value = {'True': 1.0, 'False': 0.0}.get(value, value)
>>         return value
>>
>> I wondered why True and False are converted to floats? It seems strings
>> like True and False would be better, or integers. Is there some database
>> that can not store booleans where this is useful?
>
> Right.  If anything relies on that behaviour, it should probably be
> changed anyway.
>
> I think the strings 'True' and 'False' could be ignored, but we could
> also convert them to proper booleans if we want it to be more like an
> actual eval().  Converting True and False to something that is not a
> boolean seems too illogical.
>
> (Since True and False are actually ints, we don't need to rename the
> function :))
>
> Best regards
> Ask


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu


More information about the ase-users mailing list