Hello, as I was trying to not use some attributes from a dataclass when creating a pandas.DataFrame, I noticed that even though the specific attribute was set as field(repr=False), it persisted in the data frame.
It would be nice to “hide” those attributes in the dict representation.
I did some tests changing two lines in the _asdict_inner function and it worked nicely.
def _asdict_inner(obj, dict_factory):
if _is_dataclass_instance(obj):
result = []
for f in fields(obj):
value = _asdict_inner(getattr(obj, f.name), dict_factory)
if not f.repr:
continue
result.append((f.name, value))
return dict_factory(result)
So, I don’t fully know the implications of this modification, but it would be nice to also remove a attribute from dict representation when repr=False, or even create a field where you choose not to pass along these attributes.