Skip to content

pad in arraypad.py changed behavior in an undocumented fashion #7353

@chiffa

Description

@chiffa

Previously this command worked:

a = [[1, 2], [3, 4]]
np.lib.pad(a, ((3, 2), (2, 3)), 'constant',
                 constant_values=((np.nan, np.nan), (np.nan, np.nan)))

However in the 1.10.4 it now returns the following stack trace:

Traceback (most recent call last):
  File "C:/Users/Andrei/PycharmProjects/Pharmacosensitivity_growth_assays/src/post_processing.py", line 477, in <module>
    all_cell_lines_arr, means_accumulator, errs_accumulator, names_accumulator = stack_data_in_range_of_interest(concs_effective_range)
  File "C:/Users/Andrei/PycharmProjects/Pharmacosensitivity_growth_assays/src/post_processing.py", line 129, in stack_data_in_range_of_interest
    mode='constant', constant_values=((np.nan, np.nan), (np.nan, np.nan)))
  File "C:\Anaconda\lib\site-packages\numpy\lib\arraypad.py", line 1358, in pad
    cast_to_int=False)
  File "C:\Anaconda\lib\site-packages\numpy\lib\arraypad.py", line 1070, in _normalize_shape
    return tuple(tuple(axis) for axis in arr.tolist())
AttributeError: 'tuple' object has no attribute 'tolist'

This is now the way of implementing the padding:

a = [[1, 2], [3, 4]]
nan_pad = np.array(((np.nan, np.nan), (np.nan, np.nan)))

np.lib.pad(a, ((3, 2), (2, 3)), 'constant',
                 constant_values=nan_pad)

Could you please add relevant documentation to the pad function in the arraypad.py?

An additional issue is that it looks like np.nan gets converted to -2147483648 which seems to be overflowing 32-bit signed integer. It does not affect my code that much, but this is an issue you might need to be aware of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions