-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unumpy array creation from string representation #289
base: master
Are you sure you want to change the base?
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:
***@***.***>
|
uncertainties
has the very useful functionufloat_fromstr
to createufloat
objects from various string representations. I thought that it would be a good symmetry to also include auarray_fromstr
function to turn string representations of arrays ofufloat
string representations intouarrays
. In particular, to re-createuarray
objects from the results ofstr(my_uarray)
(independent and uncorrelated, of course).Implementing this has a few issues. Firstly, the string representations of
numpy
arrays 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 likenumpy
arrays, can be multi-dimensional. In this case, the string representation will contain nested square brackets and newline characters. I have implementeduarray_fromstr
to 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-files
with no errors