Allow the conversion of booleans to numbers #733
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a table has a column with only
0
and1
as values, the agateTypeTester
detects aBoolean
column. If later in a script we want to merge this table with another (let's say the same dataset for another year) where the very same column has other numbers (detected as aNumber
column), we need to convert theBoolean
column toNumber
.To do it properly in user code, we need to write a dictionary or a function, to take into account
0
/False
,1
/True
andNone
. This is tiresome and subject to errors (when users might forgetNone
; also when raising exceptions which won't be agateCastError
s in this case).This change would allow an easy change of column type: we would just need to change the data type of the column to cast the values correctly.
This is also coherent with Python 2 and 3 having
bool
as a subclass ofint
(see e.g. here).