Skip to content

Add a test for data truncation when creating array from sequence of mixed numeric and string values #173

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

Closed
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
10 changes: 10 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,5 +1611,15 @@ def test_assign_obj_listoflists(self):
a[...] = [[1,2]]
assert_equal(a, [[1,2], [1,2]])

def test_string_truncation(self):
# Ticket #1990 - Data can be truncated in creation of an array from a
# mixed sequence of numeric values and strings
for numericval in [True, 1234, 123.4, complex(1, 234)]:
for stringconversion in [str, unicode, bytes]:
b = np.array([numericval, stringconversion('xx')])
assert_equal(stringconversion(b[0]), stringconversion(numericval))
b = np.array([stringconversion('xx'), numericval])
assert_equal(stringconversion(b[1]), stringconversion(numericval))

if __name__ == "__main__":
run_module_suite()