Skip to content

fix: traceback in _numpy_arrays_to_lists when 0 dim np array is provided#2954

Merged
vanpelt merged 2 commits intowandb:masterfrom
rpitonak:fix-0-dim-array
Nov 24, 2021
Merged

fix: traceback in _numpy_arrays_to_lists when 0 dim np array is provided#2954
vanpelt merged 2 commits intowandb:masterfrom
rpitonak:fix-0-dim-array

Conversation

@rpitonak
Copy link
Copy Markdown
Contributor

Description

Function _numpy_arrays_to_lists resulted in traceback when 0-dim numpy array was passed as a parameter. How to reproduce:

>>> from wandb.sdk.data_types import _numpy_arrays_to_lists
>>> import numpy as np
>>> x = _numpy_arrays_to_lists(np.array(4.0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rpitonak/workspace/github/client/wandb/sdk/data_types.py", line 2713, in _numpy_arrays_to_lists
    return [_numpy_arrays_to_lists(v) for v in payload.tolist()]
TypeError: 'float' object is not iterable

The problem is the .tolist() call. Explanation is in the numpy docs:

If a.ndim is 0, then since the depth of the nested list is 0, it will not be a list at all, but a simple Python scalar.

Testing

PR includes one test scenario for this use-case. I was not sure what is the expected behaviour if it should return [value] or scalar value. From the function definition it make sense to me that it is [value] but feedback is welcomed.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 23, 2021

Codecov Report

Merging #2954 (108a905) into master (7e53f7f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2954      +/-   ##
==========================================
+ Coverage   78.69%   78.72%   +0.02%     
==========================================
  Files         194      194              
  Lines       26544    26544              
==========================================
+ Hits        20890    20897       +7     
+ Misses       5654     5647       -7     
Flag Coverage Δ
functest 56.11% <0.00%> (+0.03%) ⬆️
unittest 70.54% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
wandb/sdk/data_types.py 84.27% <100.00%> (ø)
wandb/sdk/internal/sender.py 91.92% <0.00%> (-0.27%) ⬇️
wandb/sdk/lib/git.py 75.86% <0.00%> (ø)
wandb/sdk/wandb_run.py 87.89% <0.00%> (+0.26%) ⬆️
wandb/sdk/internal/meta.py 90.18% <0.00%> (+3.06%) ⬆️

Copy link
Copy Markdown
Contributor

@vanpelt vanpelt left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the PR! Our linter is complaining about the trailing whitespace on line 2711. Can you merge in the latest master and fix the whitespace issue?

@rpitonak
Copy link
Copy Markdown
Contributor Author

@vanpelt Thank you for the prompt review!

Fixed & rebased on top of the latest master

@rpitonak rpitonak requested a review from vanpelt November 24, 2021 07:59
Copy link
Copy Markdown
Contributor

@vanpelt vanpelt left a comment

Choose a reason for hiding this comment

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

👍

@vanpelt vanpelt merged commit ebcfd43 into wandb:master Nov 24, 2021
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.

2 participants