e2nIEE / pandapower

Convenient Power System Modelling and Analysis based on PYPOWER and pandas
https://www.pandapower.org
Other
848 stars 478 forks source link

[bug] Incorrect Pluralization in `plural_s` Function (Simple) #2180

Closed rfcordeiro closed 10 months ago

rfcordeiro commented 10 months ago

Bug report checklis

Reproducible Example

# From pandapower/tutorials/powerflow.ipyn

import pandapower as pp
import pandapower.networks

net = pandapower.networks.example_simple()
net

Issue Description and Traceback

I have identified a bug in the plural_s function within the pandapower project. The issue arises when attempting to pluralize a word based on a given number. The current implementation provides an incorrect pluralization when the number is greater than 1. The expected behavior is to return an "s" when the number is greater than 1, indicating the plural form, but the current implementation returns an empty string when the number is less than 1 but "s" when 1 or less.

This pandapower network includes the following parameter tables: -- bus (7 element) -- load (1 elements) -- sgen (1 elements) -- gen (1 elements) -- switch (8 element) -- shunt (1 elements) -- ext_grid (1 elements) -- line (4 element) -- trafo (1 elements)

In code this is where the bug is:

def plural_s(number):
    if number > 1:
        return ""
    else:
        return "s"

Supposed to be:

def plural_s(number):
    if number > 1:
        return "s"
    else:
        return ""

Expected Behavior

The expected behavior is to return an "s" when the number is greater than 1, indicating the plural form, but the current implementation returns an empty string when the number is less than 1 but "s" when 1 or less

Installed Versions

Any

Label

KS-HTK commented 7 months ago

The fix is still incorrect. In my fork I fixed this as follows:

def plural_s(number):
    return "" if number == 1 else "s"

The reason being that we do not expect number to be less than 0 but if it is 0 exactly it should get the plural s. In english (as in german aswell) the count of 0 is plural not singular.

0 lines 1 line 2 lines […]

This would be updated once #2212 is merged.