Skip to content

Commit

Permalink
fixed utils docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
pauladkisson committed Aug 27, 2024
1 parent 2c96d90 commit feb9001
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 35 deletions.
6 changes: 4 additions & 2 deletions src/neuroconv/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@


def calculate_regular_series_rate(series: np.ndarray, tolerance_decimals: int = 6) -> Optional[Real]:
"""Calculates the rate of a series as the difference between all consecutive points.
"""Calculate the rate of a series as the difference between all consecutive points.
If the difference between all time points are all the same value, then the value of
rate is a scalar otherwise it is None."""
rate is a scalar otherwise it is None.
"""
diff_ts = np.diff(series)
rounded_diff_ts = diff_ts.round(decimals=tolerance_decimals)
uniq_diff_ts = np.unique(rounded_diff_ts)
Expand Down
26 changes: 5 additions & 21 deletions src/neuroconv/utils/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class NoDatesSafeLoader(yaml.SafeLoader):

@classmethod
def remove_implicit_resolver(cls, tag_to_remove):
"""
Remove implicit resolvers for a particular tag.
"""Remove implicit resolvers for a particular tag.
Takes care not to modify resolvers in super classes.
Solution taken from https://stackoverflow.com/a/37958106/11483674
Expand Down Expand Up @@ -57,8 +56,7 @@ def exist_dict_in_list(d, ls):


def append_replace_dict_in_list(ls, d, compare_key, list_dict_deep_update: bool = True, remove_repeats: bool = True):
"""
Update the list ls with the dict d.
"""Update the list ls with the dict d.
Cases:
Expand Down Expand Up @@ -115,8 +113,7 @@ def dict_deep_update(
compare_key: str = "name",
list_dict_deep_update: bool = True,
) -> collections.abc.Mapping:
"""
Perform an update to all nested keys of dictionary d(input) from dictionary u(updating dict).
"""Perform an update to all nested keys of dictionary d(input) from dictionary u(updating dict).
Parameters
----------
Expand Down Expand Up @@ -174,7 +171,6 @@ def dict_deep_update(
d: dict
return the updated dictionary
"""

dict_to_update, dict_with_update_values = d, u
if not isinstance(dict_to_update, collections.abc.Mapping):
warnings.warn("input to update should be a dict, returning output")
Expand Down Expand Up @@ -206,7 +202,7 @@ def dict_deep_update(


class DeepDict(defaultdict):
"""A defaultdict of defaultdicts"""
"""A defaultdict of defaultdicts."""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(lambda: DeepDict(), *args, **kwargs)
Expand All @@ -222,26 +218,14 @@ def deep_update(self, other: Optional[Union[dict, "DeepDict"]] = None, **kwargs)
self[key] = value

def to_dict(self) -> dict:
"""Turn a DeepDict into a normal dictionary"""
"""Turn a DeepDict into a normal dictionary."""

def _to_dict(d: Union[dict, "DeepDict"]) -> dict:
return {key: _to_dict(value) for key, value in d.items()} if isinstance(d, dict) else d

return _to_dict(self)

def __deepcopy__(self, memodict={}):
"""
Parameters
----------
memodict: dict
unused
Returns
-------
DeepDict
"""
return DeepDict(deepcopy(self.to_dict()))

def __repr__(self) -> str:
Expand Down
11 changes: 4 additions & 7 deletions src/neuroconv/utils/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_base_schema(
return base_schema


def get_schema_from_method_signature(method: Callable, exclude: Optional[list[str]] = None) -> dict:
def get_schema_from_method_signature(method: Callable, exclude: Optional[list[str]] = None) -> dict: # noqa: D401
"""Deprecated version of `get_json_schema_from_method_signature`."""
message = (
"The method `get_schema_from_method_signature` is now named `get_json_schema_from_method_signature`."
Expand All @@ -81,8 +81,7 @@ def get_schema_from_method_signature(method: Callable, exclude: Optional[list[st


def get_json_schema_from_method_signature(method: Callable, exclude: Optional[list[str]] = None) -> dict:
"""
Get the equivalent JSON schema for a signature of a method.
"""Get the equivalent JSON schema for a signature of a method.
Also uses `docstring_parser` (NumPy style) to attempt to find descriptions for the arguments.
Expand Down Expand Up @@ -165,8 +164,7 @@ def _copy_without_title_keys(d: Any, /) -> Optional[dict]:


def fill_defaults(schema: dict, defaults: dict, overwrite: bool = True):
"""
Insert the values of the defaults dict as default values in the schema in place.
"""Insert the values of the defaults dict as default values in the schema in place.
Parameters
----------
Expand All @@ -190,8 +188,7 @@ def fill_defaults(schema: dict, defaults: dict, overwrite: bool = True):


def unroot_schema(schema: dict):
"""
Modify a json-schema dictionary to make it not root.
"""Modify a json-schema dictionary to make it not root.
Parameters
----------
Expand Down
3 changes: 1 addition & 2 deletions src/neuroconv/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


def infer_path(path: str) -> Union[PureWindowsPath, Path]:
"""
Infers and returns the appropriate path object based on the path string.
r"""Infers and returns the appropriate path object based on the path string.
Parameters
----------
Expand Down
4 changes: 1 addition & 3 deletions src/neuroconv/utils/str_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@


def human_readable_size(size_bytes: int, binary: bool = False) -> str:
"""
Convert a file size given in bytes to a human-readable format using division
and remainder instead of iteration.
"""Convert a file size given in bytes to a human-readable format using division and remainder instead of iteration.
Parameters
----------
Expand Down

0 comments on commit feb9001

Please sign in to comment.