Skip to content
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

Get network elements properties as data frame #909

Merged
merged 5 commits into from
Dec 17, 2024
Merged

Conversation

jeandemanged
Copy link
Member

@jeandemanged jeandemanged commented Dec 4, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

Related to #894, in part only, please do not close the issue when merging this PR.

What kind of change does this PR introduce?

Feature

What is the current behavior?

  • We can get network elements properties only if:
    • we know exactly the properties we are looking for (we know their keys),
    • or, we systematically use all_attributes=True in the get_<element_type> methods, in which case properties are added as columns.
  • Also, we cannot get properties of Network objects. (root network and subnetworks)

What is the new behavior (if this is a feature change)?

  • new method Network.get_elements_properties, returning a data frame of properties "row-oriented" - to be compared with the get_<element_type> methods returning properties in columns.
    We can also get properties of the network objects with this method
>>> import pypowsybl as pp
>>> network = pp.network.create_eurostag_tutorial_example1_network()
>>> network.get_elements_properties()
Empty DataFrame
Columns: [key, value]
Index: []
>>> network.add_elements_properties(id='sim1', key1='value1', key2='value2')
>>> network.add_elements_properties(id='GEN', key3='value3')
>>> network.get_elements_properties()
           type   key   value
id
sim1    NETWORK  key1  value1
sim1    NETWORK  key2  value2
GEN   GENERATOR  key3  value3

Does this PR introduce a breaking change or deprecate an API?

  • No

Other information:

Copy link
Member

@geofjamg geofjamg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeandemanged maybe we should add an "element_type" column to the datadrame to make it easy to use/associate with other dataframes ?

Copy link

@jeandemanged
Copy link
Member Author

jeandemanged commented Dec 16, 2024

@jeandemanged maybe we should add an "element_type" column to the datadrame to make it easy to use/associate with other dataframes ?

Hi @geofjamg,
Indeed
I named the column type for consistency with e.g. get_injections(), get_identificables(), get_branches() - although I am not really comfortable having a python reserved keyword as a column name...
Also added a type column to get_aliases().

Copy link

@geofjamg geofjamg merged commit 75d9ff2 into main Dec 17, 2024
9 checks passed
@geofjamg geofjamg deleted the get-elements-properties branch December 17, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants