On Fri, Dec 3, 2021 at 12:07 PM Sebastian Berg <sebastian@sipsolutions.net> wrote:
This discussion has recently surfaced again and I am wondering what the stance on it is for people?
The PR is: https://github.com/numpy/numpy/pull/19550
I.e. that things like "f{arr:.2f}" would be enabled in certain cases, at least for all floating point and complex values. I am wondering more about the general API progression here, since I do not think we have any prior art to compare to.
* NumPy arrays are N-D objects (containers), do we want f/e formatting to work for it?
Yes, I imagine this could be quite handy -- way nicer than figuring out the syntax for np.array2string. I would use this functionality myself.
* NumPy printing has a lot more option than just how to format each element. Are we happy to say that implemeting `.2f` is fine without unlocking other things?
If we want to add support for custom whole array formatting in the future, I think it would be reasonable to constrain ourselves to backwards compatible extensions of elementwise formatting.
* Some formatting might come with an expectation that the result has that length `f"{3.123:30e}"` gas a length of 30, but for an array that is obviously not true? Do we care about that?
I'm not concerned about this. If you aren't checking the types of arguments that you are trying to format today, you are already going to encounter surprising errors when string formatting fails.