IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
235 stars 120 forks source link

`set_meta` is backwards #417

Closed znicholls closed 3 years ago

znicholls commented 4 years ago

Standard python syntax for setting values in dictionaries is dict[key] = value. pyam's set_meta instead uses set_meta(value, key). Am I the only one who finds this backwards or is this something that could be changed in an (API-breaking) version in future?

znicholls commented 4 years ago

@danielhuppmann thoughts?

danielhuppmann commented 4 years ago

Three answers:

  1. I never thought of this as a dictionary (because it's about columns in a dataframe). That's why the arguments are actually called value and (column) name.
  2. The name arg is optional because if value is a named series, the series name is used, so changing the order is problematic.
  3. Rather than changing the API of set_meta(), I would rather suggest to add a new (additional) setter-method
    df[name] = value

    where value can be a str, number, list of correct length, or (indexed) series.

znicholls commented 4 years ago

Nice nice nice

danielhuppmann commented 3 years ago

Closing as no further comment for almost a year.