Skip to content

Commit

Permalink
run docformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Feb 20, 2024
1 parent 848c646 commit 8c74a82
Show file tree
Hide file tree
Showing 446 changed files with 2,482 additions and 4,312 deletions.
3 changes: 1 addition & 2 deletions src/gluonts/core/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@


def fqname_for(obj: Any) -> str:
"""
Returns the fully qualified name of ``obj``.
"""Returns the fully qualified name of ``obj``.
Parameters
----------
Expand Down
25 changes: 10 additions & 15 deletions src/gluonts/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@


def from_hyperparameters(cls: Type[A], **hyperparameters) -> A:
"""
Reflectively create an instance of a class with a :func:`validated`
"""Reflectively create an instance of a class with a :func:`validated`
initializer.
Parameters
Expand Down Expand Up @@ -72,8 +71,7 @@ def from_hyperparameters(cls: Type[A], **hyperparameters) -> A:

@singledispatch
def equals(this: Any, that: Any) -> bool:
"""
Structural equality check between two objects of arbitrary type.
"""Structural equality check between two objects of arbitrary type.
By default, this function delegates to :func:`equals_default_impl`.
Expand Down Expand Up @@ -108,8 +106,7 @@ def equals(this: Any, that: Any) -> bool:


def equals_default_impl(this: Any, that: Any) -> bool:
"""
Default semantics of a structural equality check between two objects of
"""Default semantics of a structural equality check between two objects of
arbitrary type.
Two objects ``this`` and ``that`` are defined to be structurally equal
Expand Down Expand Up @@ -213,8 +210,7 @@ def skip_encoding(v: Any) -> bool:


class BaseValidatedInitializerModel(BaseModel):
"""
Base Pydantic model for components with :func:`validated` initializers.
"""Base Pydantic model for components with :func:`validated` initializers.
See Also
--------
Expand All @@ -223,20 +219,19 @@ class BaseValidatedInitializerModel(BaseModel):
"""

class Config(BaseConfig):
"""
`Config <https://pydantic-docs.helpmanual.io/#model-config>`_ for the
Pydantic model inherited by all :func:`validated` initializers.
"""`Config <https://pydantic-docs.helpmanual.io/#model-config>`_ for
the Pydantic model inherited by all :func:`validated` initializers.
Allows the use of arbitrary type annotations in initializer parameters.
Allows the use of arbitrary type annotations in initializer
parameters.
"""

arbitrary_types_allowed = True


def validated(base_model=None):
"""
Decorates an ``__init__`` method with typed parameters with validation and
auto-conversion logic.
"""Decorates an ``__init__`` method with typed parameters with validation
and auto-conversion logic.
>>> class ComplexNumber:
... @validated()
Expand Down
20 changes: 7 additions & 13 deletions src/gluonts/core/serde/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ class Kind(str, Enum):

@singledispatch
def encode(v: Any) -> Any:
"""
Transforms a value `v` as a serializable intermediate representation (for
example, named tuples are encoded as dictionaries). The intermediate
"""Transforms a value `v` as a serializable intermediate representation
(for example, named tuples are encoded as dictionaries). The intermediate
representation is then recursively traversed and serialized either as
Python code or as JSON string.
Expand Down Expand Up @@ -252,10 +251,8 @@ def encode_from_state(v: Stateful) -> Any:

@encode.register(PurePath)
def encode_path(v: PurePath) -> Any:
"""
Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~PurePath` class.
"""
"""Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~PurePath` class."""
return {
"__kind__": Kind.Instance,
"class": fqname_for(v.__class__),
Expand All @@ -265,10 +262,8 @@ def encode_path(v: PurePath) -> Any:

@encode.register(BaseModel)
def encode_pydantic_model(v: BaseModel) -> Any:
"""
Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~BaseModel` class.
"""
"""Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~BaseModel` class."""
return {
"__kind__": Kind.Instance,
"class": fqname_for(v.__class__),
Expand All @@ -288,8 +283,7 @@ def encode_partial(v: partial) -> Any:


def decode(r: Any) -> Any:
"""
Decodes a value from an intermediate representation `r`.
"""Decodes a value from an intermediate representation `r`.
Parameters
----------
Expand Down
11 changes: 5 additions & 6 deletions src/gluonts/core/serde/_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def unwrap(self) -> T:

@dataclasses.dataclass
class OrElse(AnyLike):
"""
A default field for a dataclass, that uses a function to calculate the
"""A default field for a dataclass, that uses a function to calculate the
value if none was passed.
The function can take arguments, which are other fields of the annotated
Expand Down Expand Up @@ -120,12 +119,12 @@ def dataclass(
unsafe_hash=False,
frozen=False,
):
"""
Custom dataclass wrapper for serde.
"""Custom dataclass wrapper for serde.
This works similar to the ``dataclasses.dataclass`` and
``pydantic.dataclasses.dataclass`` decorators. Similar to the ``pydantic``
version, this does type checking of arguments during runtime.
``pydantic.dataclasses.dataclass`` decorators. Similar to the
``pydantic`` version, this does type checking of arguments during
runtime.
"""

# assert frozen
Expand Down
6 changes: 2 additions & 4 deletions src/gluonts/core/serde/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@


def dump_json(o: Any, indent: Optional[int] = None) -> str:
"""
Serializes an object to a JSON string.
"""Serializes an object to a JSON string.
Parameters
----------
Expand All @@ -56,8 +55,7 @@ def dump_json(o: Any, indent: Optional[int] = None) -> str:


def load_json(s: str) -> Any:
"""
Deserializes an object from a JSON string.
"""Deserializes an object from a JSON string.
Parameters
----------
Expand Down
13 changes: 4 additions & 9 deletions src/gluonts/core/serde/flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

"""
Flat encoding for serde.
"""Flat encoding for serde.
`flat.encode` always returns a flat dictionary, where keys contain information
for nested objects::
Expand Down Expand Up @@ -42,9 +41,7 @@ class Outer(NamedTuple):


def join(a, b, sep="."):
"""
Joins `a` and `b` using `sep`.
"""
"""Joins `a` and `b` using `sep`."""
if not a:
return b

Expand Down Expand Up @@ -159,8 +156,7 @@ def split_path(s):


def encode(obj) -> dict:
"""
Encode a given object into a flat-dictionary.
"""Encode a given object into a flat-dictionary.
It uses the default-encoding, to then flatten the output.
"""
Expand All @@ -172,8 +168,7 @@ def encode(obj) -> dict:


def clone(data, kwargs=None):
"""
Create a copy of a given value, by calling `encode` and `decode` on it.
"""Create a copy of a given value, by calling `encode` and `decode` on it.
If `kwargs` is provided, it's possible to overwrite nested values.
"""
Expand Down
12 changes: 4 additions & 8 deletions src/gluonts/core/serde/np.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

@encode.register(np.dtype)
def encode_np_dtype(v: np.dtype) -> Any:
"""
Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~numpy.dtype` class.
"""
"""Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~numpy.dtype` class."""
return {
"__kind__": Kind.Instance,
"class": "numpy.dtype",
Expand All @@ -34,10 +32,8 @@ def encode_np_dtype(v: np.dtype) -> Any:

@encode.register(np.ndarray)
def encode_np_ndarray(v: np.ndarray) -> Any:
"""
Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~numpy.ndarray` class.
"""
"""Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~numpy.ndarray` class."""
return {
"__kind__": Kind.Instance,
"class": "numpy.array", # use "array" ctor instead of "nparray" class
Expand Down
12 changes: 4 additions & 8 deletions src/gluonts/core/serde/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

@encode.register(pd.Timestamp)
def encode_pd_timestamp(v: pd.Timestamp) -> Any:
"""
Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~pandas.Timestamp` class.
"""
"""Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~pandas.Timestamp` class."""
return {
"__kind__": Kind.Instance,
"class": "pandas.Timestamp",
Expand All @@ -34,10 +32,8 @@ def encode_pd_timestamp(v: pd.Timestamp) -> Any:

@encode.register(pd.Period)
def encode_pd_period(v: pd.Period) -> Any:
"""
Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~pandas.Period` class.
"""
"""Specializes :func:`encode` for invocations where ``v`` is an instance of
the :class:`~pandas.Period` class."""
return {
"__kind__": Kind.Instance,
"class": "pandas.Period",
Expand Down
35 changes: 11 additions & 24 deletions src/gluonts/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ def remove(self):


class LinkedList:
"""
Simple linked list, where only elements controls removal of them.
"""Simple linked list, where only elements controls removal of them.
When going out of a `let` block, the pushed environment should be destroyed
and not just the last element of the stack.
When going out of a `let` block, the pushed environment should be
destroyed and not just the last element of the stack.
"""

def __init__(self, elements=()):
Expand All @@ -128,9 +127,7 @@ def push(self, val):
return self.end

def last(self):
"""
Peek last value.
"""
"""Peek last value."""
return self.end.val

def reverse(self):
Expand Down Expand Up @@ -251,9 +248,7 @@ def _dependency(self, name, fn):
self._dependencies[name] = Dependency(fn, dependencies)

def _get(self, key, default=None):
"""
Like `dict.get`.
"""
"""Like `dict.get`."""
try:
return self[key]
except KeyError:
Expand Down Expand Up @@ -289,8 +284,7 @@ def __getattribute__(self, key):
return self[key]

def _set_(self, dct, key, value):
"""
Helper method to assign item to a given dictionary.
"""Helper method to assign item to a given dictionary.
Uses `_types` to type-check the value, before assigning.
"""
Expand Down Expand Up @@ -320,8 +314,7 @@ def _set(self, key, value):
self._set_(self._chain.last(), key, value)

def _push(self, **kwargs):
"""
Add new entry to our chain-map.
"""Add new entry to our chain-map.
Values are type-checked.
"""
Expand All @@ -341,8 +334,7 @@ def __repr__(self):
return f"<Settings [{inner}]>"

def _let(self, **kwargs) -> "_ScopedSettings":
"""
Create a new context, where kwargs are added to the chain::
"""Create a new context, where kwargs are added to the chain::
with settings._let(foo=42):
assert settings.foo = 42
Expand All @@ -354,8 +346,7 @@ def _let(self, **kwargs) -> "_ScopedSettings":
return _ScopedSettings(self, kwargs)

def _inject(self, *keys, **kwargs):
"""
Dependency injection.
"""Dependency injection.
This will inject values from settings if available and not passed
directly::
Expand Down Expand Up @@ -428,14 +419,10 @@ def __exit__(self, *args):


def let(settings, **kwargs):
"""
`let(settings, ...)` is the same as `settings._let(...)`.
"""
"""`let(settings, ...)` is the same as `settings._let(...)`."""
return settings._let(**kwargs)


def inject(settings, *args, **kwargs):
"""
`inject(settings, ...)` is the same as `settings._inject(...)`.
"""
"""`inject(settings, ...)` is the same as `settings._inject(...)`."""
return settings._inject(*args, **kwargs)
4 changes: 1 addition & 3 deletions src/gluonts/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def __len__(self) -> int:

@dataclass
class DatasetCollection:
"""
Flattened access to a collection of datasets.
"""
"""Flattened access to a collection of datasets."""

datasets: List[Dataset]
interleave: bool = False
Expand Down
7 changes: 3 additions & 4 deletions src/gluonts/dataset/arrow/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ class File:
def infer(
path: Path,
) -> Union["ArrowFile", "ArrowStreamFile", "ParquetFile"]:
"""
Return `ArrowFile`, `ArrowStreamFile` or `ParquetFile` by inspecting
"""Return `ArrowFile`, `ArrowStreamFile` or `ParquetFile` by inspecting
provided path.
Arrow's `random-access` format starts with `ARROW1`, so we peek the
provided file for it.
Arrow's `random-access` format starts with `ARROW1`, so we peek
the provided file for it.
"""
with open(path, "rb") as in_file:
peek = in_file.read(6)
Expand Down
Loading

0 comments on commit 8c74a82

Please sign in to comment.