Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the conversion of booleans to numbers #733

Merged
merged 3 commits into from Feb 6, 2020

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!

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.

None yet

2 participants