Skip to content

Conversation

@lcorbasson
Copy link
Contributor

When a table has a column with only 0 and 1 as values, the agate TypeTester detects a Boolean 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 a Number column), we need to convert the Boolean column to Number.

To do it properly in user code, we need to write a dictionary or a function, to take into account 0/False, 1/True and None. This is tiresome and subject to errors (when users might forget None; also when raising exceptions which won't be agate CastErrors 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 of int (see e.g. here).

@jpmckinney
Copy link
Member

Looks good! Can you add a test?

@lcorbasson
Copy link
Contributor Author

Done, thanks!

@jpmckinney jpmckinney merged commit 916fbd4 into wireservice:master Feb 6, 2020
@lcorbasson lcorbasson deleted the boolean-to-number branch February 6, 2020 20:11
@lcorbasson lcorbasson restored the boolean-to-number branch February 7, 2020 08:24
@lcorbasson lcorbasson deleted the boolean-to-number branch February 7, 2020 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants