Closed markcoletti closed 1 year ago
This is an issue with numpy np.printoptions
. When numpy converts an array to a string, explicitly or implicitly for writing to streams, it uses a predetermined line width to insert breaks. You can bypass this by setting an arbitrarily large linewidth
parameter while using np.printoptions
as a context manager, or np.set_printoptions
to change it thereafter.
@lukepmccombs is working on this now. He's exploring native numpy
solutions for emitting CSV rows.
Here is my proposed solution:
In numpy you can override the printing function with another of your choosing via np.set_string_function
. We can use this functionality to make a print function that doesn't insert newlines and is usable for loading the arrays later. A good option for this is:
def _to_quoted_list(arr):
f'"{json.dumps(arr.tolist())}"'
which returns a quoted, single line json representation for any size array, and can be restored using json.loads
on the contents of the cell.
This should be closable now. :+1:
E.g., this should have been one row, but a carriage return was embedded in the middle of the list: