-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
bidict should be subclass of dict #18
Comments
Perhaps implement |
Thanks for raising this issue, @pacholik. The thing is, >>> from collections import Mapping
>>> from bidict import bidict
>>> b = bidict()
>>> isinstance(b, Mapping)
True I could understand the argument that being able to check Let me know what you think, and meanwhile I'll give the collections.abc docs another read, and if it's still not clear, appeal to Python-dev etc. for more expert guidance. |
I'd say, then, no need to allege via |
Cool, in that case just closed this with a documentation clarification. @pacholik, please let me know if this doesn't adequately address your use case. In general, I always appreciate meeting new bidict users (thanks for stopping by:), hearing about your use cases, and any other ways bidict could better meet them. Please let me know anything you'd like to share! |
You're welcome, and thanks for a good package. I've used it most recently to biject between database column names which aren't valid Python identifiers, and SQLAlchemy names for the same columns which are (valid Python identifiers). |
I suspect the use case is fairly common. |
um. we're looking for what, some kind of recipe w/ bidict? would need a lot of specifics for that use case. SQLA lets you put a .key on a Column if you want to deal with some friendly python name, you never need to know the real col names at all, so a use case here is not apparent to me. |
In my use case, I have a table T in a Postgres db which inherits from a base table containing common fields such as creator, updated-by, timestamps. It was convenient to have a class attribute holding the collection of fields unique to T (in fact, most but not all of those, even). In the db, the fieldnames use "kebob-case", and in a few places I need to translate those names to SQLA colnames and vice-versa. A bidict provides both the collection and the translation capability. |
Well, I know I can check for In particular df.rename checks if Anyway, thank you for your time. |
Aha. OK then maybe For now, you could convert your |
@jab it sounds vague and very specific to some part of someone's application without any context, so far not much material for the stated goal of a "documentation tip". |
@pacholik @Twangist Since it looks like this wasn't reported upstream yet, I just submitted pandas-dev/pandas#11461 in case you're interested in following there. |
Also, I ended up asking about this on the python-dev list, and https://mail.python.org/pipermail/python-dev/2015-October/142058.html suggests that bidict's current approach is sound. |
One other reason to not subclass dict is we would inherit the |
issubclass(bidict, dict)
returnsFalse
. We thus cannot pass it to function that test it. Ifdict
were at least at last place ofmro
it would be settled.The text was updated successfully, but these errors were encountered: