USEPA / ElectricityLCI

Creative Commons Zero v1.0 Universal
24 stars 10 forks source link

Globals, references to globals, and editing references of globals #221

Open dt-woods opened 6 months ago

dt-woods commented 6 months ago

There is a propensity to define global data frames (e.g., egrid_facilities in egrid_facilities.py and emissions_and_wastes_by_facility in egrid_emissions_and_waste_by_facility), then create slices of these data frames as new globals (e.g., egrid_facilities_w_fuel_region in generation_mix.py and emissions_and_wastes_by_facility in egrid_filter.py), which are then edited in other methods (e.g., in create_generation_process_df in generation.py).

The consequences of editing slices is that they also edit their reference data frame (the originals). The modification behavior of these globals is difficult to track as they occur at different timings in the code (e.g., globals are defined when a module is imported, and modified when a method is called). This makes the global data frames difficult to work with as their structure and definition change depending on what time it is accessed during the program's execution.

From a debugging and user standpoint, if this behavior is intentional, it is bad. If this behavior is unintentional, it is also bad.