Skip to content

Commit

Permalink
fix(doc): fix typos in data_loader.py and utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
spool committed Feb 5, 2024
1 parent 896f843 commit c517aac
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion python/load_data/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def clip_dataset(xa: xr.DataArray, variable: str, shapefile: str) -> xr.DataArra
Parameters
----------
xa
xArray containing a giving variable
xArray containing a given variable (e.g. rainfall)
variable
A string representing the variable to be loaded
shapefile
Expand Down
62 changes: 47 additions & 15 deletions python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def date_to_str(
out_format_str
A `strftime` format `str` to convert `date_obj` to.
Return
------
A `str` version of `date_obj` in `out_format_str` format.
Examples
--------
>>> date_to_str('20100101')
Expand Down Expand Up @@ -65,6 +69,11 @@ def date_range_to_str(
out_format_str
A `strftime` format `str` to convert `end_date` from.
Return
------
A `str` of date range from `start_date` to `end_date` in the
`out_format_str` format.
Examples
--------
>>> date_range_to_str('20100101', '20100330')
Expand All @@ -90,6 +99,10 @@ def iter_to_tuple_strs(iter_var: Iterable[Any]) -> tuple[str, ...]:
iter_var
Iterable of objects that can be converted into `strs`.
Return
------
A `tuple` of all `iter_var` elements in `str` format.
Examples
--------
>>> iter_to_tuple_strs(['cat', 1, Path('a/path')])
Expand All @@ -107,19 +120,23 @@ def path_iterdir(
Parameters
----------
path
`Path` of folder to iterate through
`Path` to folder to iterate through.
strict
Whether to raise `FileNotFoundError` if `path` not found.
Returns
-------
A `Generator` of `Paths` within folder `path`.
Yield
-----
A `Path` for each folder in `path`.
Raises
------
FileNotFoundError
Raised if `strict = True` and `path` does not exist.
Return
------
`None` if `FileNotFoundError` error and `strict` is `False`.
Examples
--------
Expand Down Expand Up @@ -163,11 +180,17 @@ def make_user(
Parameters
----------
user
user and home folder name
Name for user and home folder name to append to `user_home_path`.
password
login password
Login password.
code_path
path to copy code from to user path
`Path` to copy code from to `user` home directory.
user_home_path
Path that `user` folder will be in, often `Path('/home')` in `linux`.
Return
------
Full path to generated `user` home folder.
Examples
--------
Expand Down Expand Up @@ -203,6 +226,10 @@ def rm_user(user: str, user_home_path: Path = DEBIAN_HOME_PATH) -> str:
user_home_path
Parent path of `user` folder name.
Return
------
`user` name of account and home folder deleted.
Examples
--------
>>> import os
Expand All @@ -221,7 +248,7 @@ def rm_user(user: str, user_home_path: Path = DEBIAN_HOME_PATH) -> str:


def csv_reader(path: Path, **kwargs) -> Generator[dict[str, str], None, None]:
"""Yield a `dict` per for from file `path`.
"""Yield a `dict` per row from a `CSV` file at `path`.
Parameters
----------
Expand All @@ -230,10 +257,9 @@ def csv_reader(path: Path, **kwargs) -> Generator[dict[str, str], None, None]:
**kwargs
Additional parameters for `csv.DictReader`.
Returns
-------
:
A `Generator` of `dicts` per row from `path`.
Yield
-----
A `dict` per row from `CSV` file at `path`.
Examples
--------
Expand All @@ -249,8 +275,10 @@ def csv_reader(path: Path, **kwargs) -> Generator[dict[str, str], None, None]:
... line_num: int = writer.writerow(('user_name', 'password'))
... for user_name, password in auth_dict.items():
... line_num = writer.writerow((user_name, password))
>>> tuple(csv_reader(csv_path))
({'user_name': 'sally', 'password': 'fig*new£kid'}, {'user_name': 'george', 'password': 'tee&iguana*sky'}, {'user_name': 'susan', 'password': 'history!bill-walk'})
>>> tuple(csv_reader(csv_path)) # doctest: +NORMALIZE_WHITESPACE
({'user_name': 'sally', 'password': 'fig*new£kid'},
{'user_name': 'george', 'password': 'tee&iguana*sky'},
{'user_name': 'susan', 'password': 'history!bill-walk'})
"""
with open(path) as csv_file:
for row in DictReader(csv_file, **kwargs):
Expand All @@ -260,7 +288,7 @@ def csv_reader(path: Path, **kwargs) -> Generator[dict[str, str], None, None]:
def make_users(
file_path: Path, user_col: str, password_col: str, file_reader: Callable, **kwargs
) -> Generator[Path, None, None]:
"""Load a file of usernames and passwords to pass to `make_user`.
"""Load a file of usernames and passwords and pass each line to `make_user`.
Parameters
----------
Expand All @@ -275,6 +303,10 @@ def make_users(
**kwargs
Additional parameters for to pass to `file_reader` function.
Yield
-----
The home `Path` for each generated user.
Examples
--------
>>> import os
Expand Down

0 comments on commit c517aac

Please sign in to comment.