-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: targetting and add shape to ndarray #891
base: main
Are you sure you want to change the base?
Changes from 6 commits
2a271b1
cabeb50
2166318
da1637f
24c25dd
64089db
3c69c10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -789,13 +789,32 @@ class ndarray(TypeHandler): | |||||
:rtype: Callable | ||||||
""" | ||||||
|
||||||
def __init__(self, dtype=None): | ||||||
def __init__(self, shape: builtins.tuple[builtins.int, ...] = None, dtype=None): | ||||||
""" | ||||||
:param shape: shape of the array, optional. | ||||||
:param dtype: data-type, optional | ||||||
""" | ||||||
if shape is not None: | ||||||
for dim in shape: | ||||||
if dim < 0: | ||||||
raise TypeError( | ||||||
f"Ndarray shape must all be positive. Provided {shape}." | ||||||
) | ||||||
self.shape = shape | ||||||
self.dtype = dtype | ||||||
|
||||||
def __call__(self, value): | ||||||
result = np.array(value, copy=False) | ||||||
if self.dtype is not None: | ||||||
return np.array(value, copy=False, dtype=self.dtype) | ||||||
return np.array(value, copy=False) | ||||||
result = np.asarray(result, dtype=self.dtype) | ||||||
if self.shape is not None: | ||||||
try: | ||||||
result = result.reshape(self.shape) | ||||||
except Exception: | ||||||
raise TypeError( | ||||||
"Couldn't cast {} into an array of shape {}".format(value, self.shape) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this going to give a really big message for really big arrays?
Suggested change
Always prefer f-strings over There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh true, let me correct that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented in my last commit |
||||||
) | ||||||
return result | ||||||
|
||||||
@property | ||||||
def __name__(self): | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tuple does not have an any function but I kept the concept in my last commit.