Make GenericParameters return optional instead of empty defaults on non-existant keys#580
Conversation
|
I think |
|
Since we are breaking interfaces in any case I don't mind different names. That would in principle allow us to properly deprecate |
|
@tmadlener - ping. What's the status? |
|
Currently testing what is breaking downstream (and then fixing that if necessary) |
5e95c36 to
797386f
Compare
bdfe08b to
f8a8475
Compare
I have changed this to |
| if len(par_value) == 1: | ||
| return par_value[0] | ||
| return list(par_value) | ||
| return list(deepcopy(par_value)) |
There was a problem hiding this comment.
Why is this needed? Do the values disappear if the frame is deleted?
There was a problem hiding this comment.
They will definitely disappear if the Frame is gone. but in this case I think it's also something related to std::optional and how it combines with cppyy. I added it to fix tests, but let me check whether it's truly necessary.
There was a problem hiding this comment.
It seems to be interaction between std::optional and cppyy. Without the deepcopy, I run into the following in the tests:
130: ======================================================================
130: ERROR: test_frame_parameters (test_Frame.FrameReadTest)
130: Check that all expected parameters are available.
130: ----------------------------------------------------------------------
130: Traceback (most recent call last):
130: File "/home/tmadlener/work/AIDASoft/podio/python/podio/test_Frame.py", line 192, in test_frame_parameters
130: self.assertEqual(
130: File "/home/tmadlener/work/.spack/spackages/python/3.10.13/skylake-ubuntu22.04-gcc12.3.0/jsngvl3/lib/python3.10/unittest/case.py", line 845, in assertEqual
130: assertion_func(first, second, msg=msg)
130: File "/home/tmadlener/work/.spack/spackages/python/3.10.13/skylake-ubuntu22.04-gcc12.3.0/jsngvl3/lib/python3.10/unittest/case.py", line 1051, in assertListEqual
130: self.assertSequenceEqual(list1, list2, msg, seq_type=list)
130: File "/home/tmadlener/work/.spack/spackages/python/3.10.13/skylake-ubuntu22.04-gcc12.3.0/jsngvl3/lib/python3.10/unittest/case.py", line 976, in assertSequenceEqual
130: if seq1 == seq2:
130: SystemError: Negative size passed to PyUnicode_FromStringAndSize
There was a problem hiding this comment.
I think the problem is that the par_value (or it's underlying storage) goes out of scope without the deepcopy. Previously the getParameter returned a const& so it was kept alive by the underlying frame, so no deepcopy was necessary.
| SET( ${PROJECT_NAME}_VERSION_MAJOR 0 ) | ||
| SET( ${PROJECT_NAME}_VERSION_MINOR 99 ) | ||
| SET( ${PROJECT_NAME}_VERSION_PATCH 0 ) | ||
| SET( ${PROJECT_NAME}_VERSION_PATCH 99 ) |
There was a problem hiding this comment.
So this is the last version before 1.0 😃
There was a problem hiding this comment.
:D I would hope so. However, the main reason for this is that setting this to 99 would in principle allow us to still have patch releases, while still having pre-processor checks only compare >0.99 effectively.
In principle we could consider doing this by default after tagging a release to make it easier to detect development builds.
f8a8475 to
c08a433
Compare
This makes it possible to distinguish between set and empty values and non-existant values. Deprecate getValue and setValue and also introduce set for symmetry.
c08a433 to
c0d5907
Compare
|
@Zehvogel a quick heads up:
This bit here will require some changes to your RDataFrame code where you directly talk to the - df = df.Define("xsec_fb", "PARAMETERS.getValue<float>(\"crossSection\")")
+ df = df.Define("xsec_fb", "PARAMETERS.get<float>(\"crossSection\")") |
actually needed a - df = df.Define("xsec_fb", "PARAMETERS.getValue<float>(\"crossSection\")")
+ df = df.Define("xsec_fb", "*PARAMETERS.get<float>(\"crossSection\")")(or something intelligent :)) |
|
Ah yes, because it now also returns a |
BEGINRELEASENOTES
GenericParametersreturnstd::optionalon non-existant keys instead of empty defaults. This allows to differentiate between empty (but set) and unset parameters, as the default value could actually be a valid parameter value for some types (e.g. integers or floats).setValueandgetValuefunctions to justsetandget. This is also a breaking change, but as far as we are aware theGenericParametersare only used internally in podio.Frame::getParameteralso return thisstd::optional. This is a breaking change that might require adaptation of existing codeENDRELEASENOTES
Fixes #576
The following PRs make this introduction work transparently and need to be merged first to not break the nightlies