Repository: OSeMOSYS/otoole

Issue:
[Bug]: Data conversion to Excel
### The Issue

If I convert from CSV to excel, and a parameter is not indexed over years but the last column is MODE_OF_OPERATION, the mode gets pivoted on

For example, TechnologyToStorage is given as: 
![image](https://user-images.githubusercontent.com/67297083/234377814-03b895d9-eeae-4f28-982f-ffe019c739f0.png)

### Expected Behavior

The pivot should only happen on the years column. The output should look like 

| REGION | TECH | STORAGE | MODE | VALUE | 
|---------|-------|-----------|---------|--------|
| Simplicity | HYD2 | DAM | 1 | 1 |
| Simplicity | HYD2 | DAM | 2 | 0 |

### Steps To Reproduce

1. Clone Simplicity with `git clone https://github.com/OSeMOSYS/simplicity.git`
2. Run `otoole convert csv excel data data.xlsx config.yaml`
3. View both the `TechnologyToStorage` and `TechnologyFromStorage` sheets, which are **not** indexed over year in the CSV files


### Log output

```bash
OtooleIndexError: TechnologyFromStorage -> Indices inconsistent between config and data. Config indices are ['REGION', 'TECHNOLOGY', 'STORAGE', 'MODE_OF_OPERATION']. Data indices are ['REGION', 'TECHNOLOGY', 'STORAGE', 'YEAR'].
```

### Operating System

Linux

### What version of otoole are you running?

Error is introduced in version 1.0.2 

### Possible Solution

_No response_

### Anything else?

_No response_

Discussion:

Patch:
diff --git a/src/otoole/write_strategies.py b/src/otoole/write_strategies.py
index cfe8a2e..a2c1846 100644
--- a/src/otoole/write_strategies.py
+++ b/src/otoole/write_strategies.py
@@ -40,7 +40,9 @@ class WriteExcel(WriteStrategy):
 
         total_columns = len(names)
 
-        if total_columns > 3:
+        if "YEAR" not in names:
+            pivot = df.copy()
+        elif total_columns > 3:
             logger.debug("More than 3 columns for {}: {}".format(parameter_name, names))
             rows = names[0:-2]
             columns = names[-2]


Test patch:
diff --git a/tests/test_write_strategies.py b/tests/test_write_strategies.py
index 7d6aac1..af4d8b8 100644
--- a/tests/test_write_strategies.py
+++ b/tests/test_write_strategies.py
@@ -92,6 +92,26 @@ class TestWriteExcel:
 
         pd.testing.assert_frame_equal(actual, expected)
 
+    def test_form_no_pivot(self, user_config):
+
+        convert = WriteExcel(user_config)  # typing: WriteExcel
+
+        # Technology to/from storage data
+        data = [
+            ["SIMPLICITY", "HYD2", "DAM", 1, 0],
+            ["SIMPLICITY", "HYD2", "DAM", 2, 1],
+        ]
+
+        df = pd.DataFrame(
+            data=data,
+            columns=["REGION", "TECHNOLOGY", "STORAGE", "MODE_OF_OPERATION", "VALUE"],
+        ).set_index(["REGION", "TECHNOLOGY", "STORAGE", "MODE_OF_OPERATION"])
+
+        actual = convert._form_parameter(df, "test_parameter", 0)
+        expected = df.copy()
+
+        pd.testing.assert_frame_equal(actual, expected)
+
     def test_write_out_empty_dataframe(self, user_config):
 
         temp_excel = NamedTemporaryFile(suffix=".xlsx")