unumpy array creation from string representation#289
unumpy array creation from string representation#289jnahlers wants to merge 8 commits intolmfit:masterfrom
Conversation
This works by converting the string representation into a numpy array using ast.literal_eval, then converting each element of the resulting array into a ufloat using ufloat_tostr.
|
@jnahlers Thanks. I have to admit that I am not an enormous fan of either I think the challenges and messy bits of But also: Is there a problem that this is solving? Like, who has string representations of arrays of ufloats that are stored in a way that needs to be parsed? That is, as opposed to a file with tables with columns for nominal values and standard errors? |
The beauty of the
Agreed! Certainly
Anyone who has to deal will |
|
It may be more appropriate for your problem to add writing/parsing support to uncertainties-pandas |
Interesting library! I am not working with |
|
my thinking is that whoever is writing the text output from pandas could
use uncertainties-pandas to write the an output file, then you can use
uncertainties-pandas to read the outfile in a DataFrame, then use
.to_numpy() to get the array of uncertainties you want.
…On Thu, Jan 30, 2025 at 7:49 AM Jannis Ahlers ***@***.***> wrote:
It may be more appropriate for your problem to add writing/parsing support
to uncertainties-pandas
https://github.com/andrewgsavage/uncertainties-pandas/blob/main/notebooks/tutorial.ipynb
Interesting library! I am not working with pandas myself, I am just
parsing a text output from pandas.
—
Reply to this email directly, view it on GitHub
<#289 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADEMLEDNPXNRFJZQ3NI7VTL2NHKSJAVCNFSM6AAAAABWEJQMGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMRTG43DSNZVHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
uncertaintieshas the very useful functionufloat_fromstrto createufloatobjects from various string representations. I thought that it would be a good symmetry to also include auarray_fromstrfunction to turn string representations of arrays ofufloatstring representations intouarrays. In particular, to re-createuarrayobjects from the results ofstr(my_uarray)(independent and uncorrelated, of course).Implementing this has a few issues. Firstly, the string representations of
numpyarrays use spaces to separate values. Therefore, string representations of ufloats that contain spaces (as supported byufloat_fromstr) cannot (straightforwardly) be supported byuarray_fromstr.uarrays, just likenumpyarrays, can be multi-dimensional. In this case, the string representation will contain nested square brackets and newline characters. I have implementeduarray_fromstrto support this using a slightly hacky workaround that relies onast.literal_eval. While this is much safer thaneval, there are still some important security considerations.pre-commit run --all-fileswith no errors