Skip to content

Commit

Permalink
Added proper positional arguments to exists at ivy/general.py and arr…
Browse files Browse the repository at this point in the history
…ay/general.py. Implemented container exists instance method with docstrings
  • Loading branch information
SpyingEnvelope committed Sep 4, 2023
1 parent c5a0510 commit b79d1b2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ivy/data_classes/array/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def value_is_nan(self: ivy.Array, /, *, include_infs: bool = True) -> bool:
"""
return ivy.value_is_nan(self, include_infs=include_infs)

def exists(self: ivy.Array) -> bool:
def exists(self: ivy.Array, /) -> bool:
"""
ivy.Array instance method variant of ivy.exists. This method simply wraps the
function, and so the docstring for ivy.exists also applies to this method with
Expand All @@ -1002,7 +1002,7 @@ def exists(self: ivy.Array) -> bool:
Returns
-------
ret
True if x is not None, else False.
True if input is not None, else False.
Examples
--------
Expand Down
54 changes: 54 additions & 0 deletions ivy/data_classes/container/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -4242,3 +4242,57 @@ def strides(
A tuple containing the strides.
"""
return self.static_strides(self)

@staticmethod
def static_exists(x: ivy.Container, /) -> ivy.Container:
"""
ivy.Container instance method variant of ivy.exists. This method simply wraps
the function, and so the docstring for ivy.exists also applies to this method
with minimal changes.
Parameters
----------
x
input container.
Returns
-------
ret
True if x is not None, else False.
Examples
--------
>>> x = ivy.Container(a=[1,2,3,4], b=[])
>>> y = x.exists()
>>> print(y)
{ a: True, b: True }
>>> x = ivy.Container(a=None, b=[1,2])
>>> y = x.exists()
>>> print(y)
{ a: False, b: True }
>>> x = ivy.Container(a={"d": 1, "c": 3}, b=None)
>>> y = x.exists()
>>> print(y)
{ a: { c: True, d: True }, b: False }
"""
return ContainerBase.cont_multi_map_in_function("exists", x)

def exists(self: ivy.Container, /) -> ivy.Container:
"""
ivy.Container instance method variant of ivy.exists. This method simply wraps
the function, and so the docstring for ivy.exists also applies to this method
with minimal changes.
Parameters
----------
x
input container.
Returns
-------
ret
True if x is not None, else False.
"""
return self.static_exists(self)

0 comments on commit b79d1b2

Please sign in to comment.