Skip to content

Modified Error messages #411

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

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions pydatastructs/linear_data_structures/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ class OneDimensionalArray(Array):
__slots__ = ['_size', '_data', '_dtype']

def __new__(cls, dtype=NoneType, *args, **kwargs):
if dtype is NoneType or len(args) not in (1, 2):
raise ValueError("1D array cannot be created due to incorrect"
" information.")
if dtype is NoneType:
raise ValueError("Data type is not defined.")
if len(args) not in (1, 2):
raise ValueError("Too few arguments to create a 1D array,"
" pass either size of the array"
" or list of elements or both.")
obj = Array.__new__(cls)
obj._dtype = dtype
if len(args) == 2:
Expand All @@ -90,7 +93,7 @@ def __new__(cls, dtype=NoneType, *args, **kwargs):
raise TypeError("Expected type of size is int and "
"expected type of data is list/tuple.")
if size != len(data):
raise ValueError("Conflict in the size %s and length of data %s"
raise ValueError("Conflict in the size, %s and length of data, %s"
%(size, len(data)))
obj._size, obj._data = size, data

Expand Down Expand Up @@ -181,9 +184,11 @@ class MultiDimensionalArray(Array):
__slots__ = ['_sizes', '_data', '_dtype']

def __new__(cls, dtype: type = NoneType, *args, **kwargs):
if dtype is NoneType or not args:
raise ValueError("Array cannot be created due to incorrect"
" information.")
if dtype is NoneType:
raise ValueError("Data type is not defined.")
elif not args:
raise ValueError("Too few arguments to create a multi dimensional array,"
" pass dimensions.")
if len(args) == 1:
obj = Array.__new__(cls)
obj._dtype = dtype
Expand All @@ -194,8 +199,8 @@ def __new__(cls, dtype: type = NoneType, *args, **kwargs):
dimensions = args
for dimension in dimensions:
if dimension < 1:
raise ValueError("Array cannot be created due to incorrect"
" dimensions.")
raise ValueError("Number of dimensions"
" cannot be less than 1")
n_dimensions = len(dimensions)
d_sizes = []
index = 0
Expand Down