Skip to content

Commit

Permalink
Extend documentation of FileFinder and FileContainer (#141)
Browse files Browse the repository at this point in the history
* extend documentation of FileFinder and FileContainer

* add meta, paths and items to api.rst

* CHANGELOG

* run velin
  • Loading branch information
veni-vidi-vici-dormivi authored Jan 7, 2025
1 parent 762eca8 commit 389ceb8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

## v0.4.0 - unreleased
- Added documentation files for readthedocs ([#134](https://github.com/mpytools/filefisher/pull/134))
and extended the documentation with usage ([#135](https://github.com/mpytools/filefisher/pull/135)),
and installation instructions ([#136](https://github.com/mpytools/filefisher/pull/136))
and extended the documentation with usage ([#135](https://github.com/mpytools/filefisher/pull/135)), installation instructions ([#136](https://github.com/mpytools/filefisher/pull/136)), as well as extension of the api documentation ([#141](https://github.com/mpytools/filefisher/pull/141))
- Added two methods to find _exactly_ one file or path (and raise an error otherwise):
`FileFinder.find_single_file` and `FileFinder.find_single_path`
([#101](https://github.com/mpytools/filefisher/pull/101)).
Expand Down
3 changes: 3 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ FileContainer
:toctree: generated/

~FileContainer
~FileContainer.meta
~FileContainer.paths
~FileContainer.items
~FileContainer.search
~FileContainer.concat

Expand Down
50 changes: 38 additions & 12 deletions filefisher/_filefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ def find_single_path(self, keys=None, **keys_kwargs) -> "FileContainer":
Raises
------
ValueError : if more or less than one path is found
ValueError
if more or less than one path is found.
"""

return self.path.find_single(keys, **keys_kwargs)
Expand All @@ -557,7 +558,8 @@ def find_single_file(self, keys=None, **keys_kwargs) -> "FileContainer":
Raises
------
ValueError : if more or less than one file is found
ValueError
if more or less than one file is found.
"""

return self.full.find_single(keys, **keys_kwargs)
Expand Down Expand Up @@ -585,14 +587,6 @@ def __init__(self, df: pd.DataFrame):
----------
df : pd.DataFrame
DataFrame with info about found paths from FileFinder.
Properties
----------
meta : list[dict[str, Any]]
List of metadata dictionaries.
paths : list[str]
List of paths.
"""

self.df = df
Expand Down Expand Up @@ -623,17 +617,35 @@ def __getitem__(self, key):

@property
def meta(self) -> list[dict[str, Any]]:
"""Return metadata as list of dictionaries"""
return self.df.to_dict("records")

@property
def paths(self) -> list[str]:
"""Return paths as list"""
return self.df.index.to_list()

def items(self) -> Generator[tuple[str, dict[str, Any]], None, None]:
"""Return a generator of (path, metadata) tuples"""
for index, element in self.df.iterrows():
yield index, element.to_dict()

def combine_by_key(self, keys=None, sep="."):
"""combine columns
Parameters
----------
keys : list[str], optional
List of keys to combine. If None, all keys are combined.
sep : str, default "."
Separator between the keys.
Returns
-------
pd.Series
pd.Series with combined columns where the keys are seperated by `sep`.
"""
warnings.warn(
"`combine_by_key` has been deprecated and will be removed in a future version",
FutureWarning,
Expand All @@ -642,7 +654,21 @@ def combine_by_key(self, keys=None, sep="."):
return self._combine_by_keys(keys=keys, sep=sep)

def _combine_by_keys(self, keys=None, sep="."):
"""combine columns"""
"""combine columns
Parameters
----------
keys : list[str], optional
List of keys to combine. If None, all keys are combined.
sep : str, default "."
Separator between the keys.
Returns
-------
pd.Series
pd.Series with combined columns where the keys are seperated by `sep`.
"""

if keys is None:
keys = list(self.df.columns)
Expand All @@ -654,7 +680,7 @@ def search(self, **query):
Parameters
----------
**query: Mapping[str, str | int | list[str | int]]
**query : Mapping[str, str | int | list[str | int]]
Search query.
Notes
Expand Down

0 comments on commit 389ceb8

Please sign in to comment.