Skip to content

fix #203 : raise error in array creation functions - #220

Merged
gdementen merged 1 commit into
larray-project:masterfrom
alixdamman:raise_error_array_creation_functions
Apr 24, 2017
Merged

gdementen merged 1 commit into
larray-project:masterfrom
alixdamman:raise_error_array_creation_functions

Conversation

@alixdamman

Copy link
Copy Markdown
Collaborator

fix #203

@alixdamman
alixdamman force-pushed the raise_error_array_creation_functions branch from fe0d9f1 to 567cf5f Compare April 13, 2017 10:51
@alixdamman alixdamman changed the title Raise error array creation functions (issue 203) fix #203 : raise error in array creation functions Apr 13, 2017
Comment thread larray/core.py Outdated
return LArray(np.empty_like(array.data, dtype, order), array.axes, title)


# No need to add @_check_axes_argument, `axes` argument will be checked in empty

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is needed, because what needs to be checked is fill_value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will return an error if fill_value is an integer. But I can test if fill_value is not an Axis before to call empty inside full

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so rather than "no need to add...", the comment should be something like: "we cannot use ... because an integer fill_value would be considered as an error"

Comment thread larray/core.py
if len(args) > 1 and isinstance(args[1], (int, Axis)):
raise ValueError("If you want to pass several axes or dimension lengths to {}, "
"you must pass them as a list (using []) or tuple (using()).".format(func.__name__))
return func(*args, **kwargs)

@gdementen gdementen Apr 18, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when wrapping a function, you need to copy its __name__ and __doc__ and possibly other stuff, or preferably, use functools.wraps on the wrapper.

@alixdamman
alixdamman force-pushed the raise_error_array_creation_functions branch from 567cf5f to f8783ba Compare April 18, 2017 10:20
Comment thread larray/core.py Outdated
FO | 0 | 1
"""
if isinstance(fill_value, Axis):
raise TypeError("`fill_value` must be a numeric value")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better to raise the same error than other creation functions?

Comment thread larray/core.py Outdated
return LArray(np.empty_like(array.data, dtype, order), array.axes, title)


# No need to add @_check_axes_argument, `axes` argument will be checked in empty

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so rather than "no need to add...", the comment should be something like: "we cannot use ... because an integer fill_value would be considered as an error"

…d as func(axis1, axis2, ...) instead of func([axis1, axis2], ...)
@alixdamman
alixdamman force-pushed the raise_error_array_creation_functions branch from f8783ba to 30226ad Compare April 18, 2017 11:36
@gdementen

Copy link
Copy Markdown
Contributor

LGTM

@gdementen
gdementen merged commit 119ef1d into larray-project:master Apr 24, 2017
@alixdamman
alixdamman deleted the raise_error_array_creation_functions branch April 24, 2017 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zeros(axis1, axis2) should raise an error

2 participants