Skip to content

Commit a158395

Browse files
pratikglczgdp1807
andauthored
Modified error messages in linear_data_structures.arrays (#411)
Co-authored-by: Gagandeep Singh <[email protected]>
1 parent f391ab6 commit a158395

File tree

1 file changed

+14
-9
lines changed
  • pydatastructs/linear_data_structures

1 file changed

+14
-9
lines changed

pydatastructs/linear_data_structures/arrays.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ class OneDimensionalArray(Array):
6868
__slots__ = ['_size', '_data', '_dtype']
6969

7070
def __new__(cls, dtype=NoneType, *args, **kwargs):
71-
if dtype is NoneType or len(args) not in (1, 2):
72-
raise ValueError("1D array cannot be created due to incorrect"
73-
" information.")
71+
if dtype is NoneType:
72+
raise ValueError("Data type is not defined.")
73+
if len(args) not in (1, 2):
74+
raise ValueError("Too few arguments to create a 1D array,"
75+
" pass either size of the array"
76+
" or list of elements or both.")
7477
obj = Array.__new__(cls)
7578
obj._dtype = dtype
7679
if len(args) == 2:
@@ -90,7 +93,7 @@ def __new__(cls, dtype=NoneType, *args, **kwargs):
9093
raise TypeError("Expected type of size is int and "
9194
"expected type of data is list/tuple.")
9295
if size != len(data):
93-
raise ValueError("Conflict in the size %s and length of data %s"
96+
raise ValueError("Conflict in the size, %s and length of data, %s"
9497
%(size, len(data)))
9598
obj._size, obj._data = size, data
9699

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

183186
def __new__(cls, dtype: type = NoneType, *args, **kwargs):
184-
if dtype is NoneType or not args:
185-
raise ValueError("Array cannot be created due to incorrect"
186-
" information.")
187+
if dtype is NoneType:
188+
raise ValueError("Data type is not defined.")
189+
elif not args:
190+
raise ValueError("Too few arguments to create a multi dimensional array,"
191+
" pass dimensions.")
187192
if len(args) == 1:
188193
obj = Array.__new__(cls)
189194
obj._dtype = dtype
@@ -194,8 +199,8 @@ def __new__(cls, dtype: type = NoneType, *args, **kwargs):
194199
dimensions = args
195200
for dimension in dimensions:
196201
if dimension < 1:
197-
raise ValueError("Array cannot be created due to incorrect"
198-
" dimensions.")
202+
raise ValueError("Number of dimensions"
203+
" cannot be less than 1")
199204
n_dimensions = len(dimensions)
200205
d_sizes = []
201206
index = 0

0 commit comments

Comments
 (0)