Return dictionaries instead of tuples
See original GitHub issueI found it a bit inconvenient to have fit_sdm_cec_sam() return a tuple. I think returning a dictionary with ['I_L_ref', 'I_o_ref', 'R_sh_ref', 'R_s', 'a_ref', 'Adjust'] keys would be much more convenient and safe.
The same goes for calcparams_cec(), which could return a dictionary with ['photocurrent', 'saturation_current', 'resistance_series', 'resistance_shunt', 'nNsVth'] keys instead.
I think that is more Pythonic (explicit is better than implicit and readability counts).
Also, more convenient API-wise:
cec_parameters = fit_sdm_cec_sam(...)
sd_parameters = calcparams_cec(..., **cec_parameters)
curve_info = singlediode(..., **sd_parameters)
The tests could be simplified as well. They currently look like:
I_L_ref, I_o_ref, R_sh_ref, R_s, a_ref, Adjust = ivtools.fit_sdm_cec_sam(...)
expected = pd.Series(get_cec_params_cansol_cs5p_220p['output'])
modeled = pd.Series(index=expected.index, data=np.nan)
modeled['a_ref'] = a_ref
modeled['I_L_ref'] = I_L_ref
modeled['I_o_ref'] = I_o_ref
modeled['R_sh_ref'] = R_sh_ref
modeled['R_s'] = R_s
modeled['Adjust'] = Adjust
assert np.allclose(modeled.values, expected.values, rtol=5e-2)
They could look like:
modeled = ivtools.fit_sdm_cec_sam(...)
expected = get_cec_params_cansol_cs5p_220p['output']
assert modeled == pytest.approx(expected, rel=5e-2)
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (19 by maintainers)
Top Results From Across the Web
Alternative to returning dictionaries instead of tuples from user ...
I frequently find myself returning dictionaries instead of tuples when defining functions in Python with many outputs (say 5-20).
Read more >Python | Convert dictionary to list of tuples - GeeksforGeeks
Below are various methods to convert dictionary to list of tuples. Method #1: Using list comprehension. Python3. Python3 ...
Read more >Python Return Multiple Values – How to Return a Tuple, List ...
In this article, we'll explore how to return multiple values from these data structures: tuples, lists, and dictionaries.
Read more >When to use a dictionary vs tuple in Python
In python, dictionary is mutable object. Other side, tuple is immutable object. if you need to change ...
Read more >5. Data Structures — Python 3.11.1 documentation
Performing list(d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I don’t really have a strong opinion here, and there are already a lot of voices, but I will just mention this: beware of classes. They can be useful if used thoughtfully, but they
As usually I may be completely wrong about this but I have seen otherwise. PVMismatch is a case in point. With cells as a “class” we have to do a lot of secret magic to keep the memory load down. This might be less of an issue if the cells’ info was all in one giant NumPy array or other efficient memory container.
In my experience maintaining pvlib, it’s been easier to deal with things that require order (positional args and returned tuples) than things that require labels (keyword args and returned dicts or DataFrames). I do use a lot of dicts, Series, and DataFrames in my work, so I certainly appreciate their general value. It just seems they’re harder for a more general purpose library. As I mentioned in the linked issue, I’d really like to read a blog post about this kind of API design question in scientific computing.
It’s also not clear to me that you’d actually need to switch to keyword arguments to achieve the input simplification you’re after. Examples showing that it can be done with positional arguments:
The test simplification could work with a tuple too: