So many people here explaining why Python works that way, but what's the reason for numpy to introduce its own boolean? Is the Python boolean somehow insufficient?
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
Data typing is important. If two types do not have the same in-memory representation but you treat them like they do, you're inviting a lot of potential bugs and security vulnerabilities to save a few characters.
ETA: The WONTFIX is absolutely the correct response here. This would allow devs to shoot themselves in the foot for no real gain, eliminating the benefit of things like mypy. Type safety is your friend and will keep you from making simple mistakes.
bool_
via Numpy is its own object, and it's fundamentally different from bool
in Python (which is itself a subclass of int
, whereas bool_
is not).
They are used similarly, but they're similar in the same way a fork and a spork can both be used to eat spaghetti.
I/O Issues are problems that come with the territory for scripting languages like python. Its why I prefer to use bash for scripting instead, because in bash, all I/O are strings. And if there are ever any conflicts, well that's what awk/sed/Perl are for.
Regex is Turing Complete after all.
Well yeah just because they kinda mean the same thing it doesn't mean that they are the same. I can wholly understand why they won't "fix" your inconvenience.
Unless I'm missing something big here, saying they "kinda mean the same thing" is a hell of an understatement.
They are two different data types with potentially different in-memory representations.
Well, yeah, but they do mean the exact same thing, hopefully: true or false
Although thinking about it, someone above mentioned that the numpy bool_
is an object, so I guess that is really: true or false or null/None
This explanation is pretty clear cut
What exactly is your use case for treating
np.bool_
andbool
as interchangeable? Ifnp.bool_
isn't a subclass ofbool
according to Python itself, then allowing one to be used where the other is expected just seems like it would prevent mypy from noticing bugs that might arise from code that expects abool
but gets annp.bool_
(or vice versa), and can only handle one of those correctly.
mpy and numpy are opensource. You could always implement the fix you need yourself ?
They've declared it as WONTFIX, so unless you're suggesting that OP creates a fork of numpy, that's not going to work.