perf: Add __slots__ to all DTypes#3194
Conversation
|
I'm thinking |
FBruzzesi
left a comment
There was a problem hiding this comment.
Thanks @dangotbanned - I am quite a big fan of slots so I am definitely onboarded 😂
I left a comment to (hopefully) lower some of the maintenance effort
Noticed how slow it was during debugging (too much repeating)
Bug discovered by @FBruzzesi #3194 (comment) Now I need to fix 200/222 failures 😂
FBruzzesi
left a comment
There was a problem hiding this comment.
Thanks @dangotbanned - I left a non-bloking nitpick comment for the error message but feel free to ignore it if you don't like it much better.
Co-authored-by: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com>
|
Sorry for asking here (I'm also not a maintainer of this library, but just sumbled over this issue): Instead of manually having to explicitly set Sorry again, just a curious question from an outsider! |
Hey @jonded94 - no need to apologize, actually thank you for questioning these kind of choices. We should definitely not dive into a solution without thinking about pros and cons of different approaches.
I feel you, I tried to propose a metaclass that can lower such burden :) and #3201 is using something towards such direction, so let's see if it makes it in the main branch soon as well.
We probably give it for granted in many places, but the main idea is that we want to have an API which is very close to the polars one. That's not always possible, but I would rather not have a discrepancy such as: from dataclasses import is_dataclass
from polars import DataType
from narwhals.dtypes import DType
is_dataclass(DataType)
# False
is_dataclass(DType)
# Trueor similarly: from collections import namedtuple
import polars as pl
Int64 = namedtuple('Int64', field_names=())
isinstance(pl.Int64(), tuple), isinstance(Int64(), tuple)
# False, TrueI hope it makes sense 😇 |

Closes #3185
What type of PR is this? (check all applicable)
If you have comments or can explain your changes, please do so below
nw.dtypesCheck ifstable.*needs empty__slots__(It did)