-
Notifications
You must be signed in to change notification settings - Fork 2
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
make FileContainer
iteration more dict-like
#108
Comments
Really? Intuitively I would have said the other way around? for filename, meta in fc.items():
pass |
Yes you are probably right. I think that comes from datalist where it's the other way round 😕 (where |
Which datalist? |
|
I started implementing this and I am no longer sure we should use We should probably deprecate
@property
def meta(self) -> list[dict]:
return self.df.to_dict("records")
@property
def paths(self) -> list[str]:
return fc.df.index.to_list()
def items(self) -> tuple[str, dict]:
for path, element in self.df.iterrows():
yield path, element.to_dict()
# ===============================
def __iter__(self):
warnings.warn(
"iterating over a FileContainer now only yields the path. To restore"
" the old behaviour and/ or supress this warning loop over `.items()`"
" `.keys()` or `.values()`."
)
yield from self.index
def keys(self):
"""iterate over the paths"""
yield from self.index
def values(self):
for __, element in self.df.iterrows():
yield element.to_dict() |
Hm I like the properties and the |
Currently we iterate
FileContainer
ashttps://github.com/mathause/filefinder/blob/aef8d48356b814e70bfbcd6ffec8025949d82d3b/filefinder/_filefinder.py#L552
Often the
filename
is not needed but.create_filename(**meta)
is used, so we should make this more dict-like and add.keys()
,.values()
, and.items()
toFileContainer
to allow iteration over whatever is needed. Now the difficult question: which should be which? My initial feeling:meta -> keys
,filename -> values
. But I am not 100% sure.NOTE: there is no good way to deprecate
__iter__
.@veni-vidi-vici-dormivi
The text was updated successfully, but these errors were encountered: