Repository: electricitymaps/electricitymaps-contrib

Issue:
Taiwan TW.py parser fails
Help wanted! :)
Taiwan isn't showing any data at the moment and the parser has to be fixed.

This is the error message for TW.py of the logger:
'DataFrame' object has no attribute 'convert_objects'

I get this warning running the parser locally (probably with older versions of the libraries):
```
Python36-32/TW.py", line 32
    objData = objData.convert_objects(convert_numeric=True)
FutureWarning: convert_objects is deprecated.  To re-infer data dtypes for object columns, use DataFrame.infer_objects()
For all other conversions use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.

```
But I still recieve an output:

```
{'zoneKey': 'TW', 'datetime': datetime.datetime(2019, 10, 4, 16, 0, tzinfo=tzfile('ROC')), 'production': {'coal': 9743.199999999999, 'gas': 15124.899999999998, 'oil': 681.4, 'hydro': 726.0, 'nuclear': 3833.7000000000003, 'solar': 576.2239999999999, 'wind': 18.900000000000006, 'unknown': 1435.9}, 'capacity': {'coal': 13097.2, 'gas': 16866.4, 'oil': 2572.1, 'hydro': 2091.4999999999995, 'hydro storage': 2602.0, 'nuclear': 3872.0, 'solar': 3144.4, 'wind': 710.9999999999999, 'unknown': 623.2}, 'storage': {'hydro': -622.3}, 'source': 'taipower.com.tw'}
```


Discussion:
I will try to get this fixed quickly.

Resolving patch:
diff --git a/parsers/TW.py b/parsers/TW.py
--- a/parsers/TW.py
+++ b/parsers/TW.py
@@ -10,7 +10,8 @@ def fetch_production(zone_key='TW', session=None, target_datetime=None, logger=N
         raise NotImplementedError('This parser is not yet able to parse past dates')
 
     url = 'http://www.taipower.com.tw/d006/loadGraph/loadGraph/data/genary.txt'
-    response = requests.get(url)
+    s = session or requests.Session()
+    response = s.get(url)
     data = response.json()
 
     dumpDate = data['']
@@ -29,17 +30,18 @@ def fetch_production(zone_key='TW', session=None, target_datetime=None, logger=N
     objData.drop('additional', axis=1, inplace=True)
     objData.drop('percentage', axis=1, inplace=True)
 
-    objData = objData.convert_objects(convert_numeric=True)
+    objData['capacity'] = pandas.to_numeric(objData['capacity'], errors='coerce')
+    objData['output'] = pandas.to_numeric(objData['output'], errors='coerce')
     production = pandas.DataFrame(objData.groupby('fueltype').sum())
     production.columns = ['capacity', 'output']
 
-    coal_capacity = production.ix['Coal'].capacity + production.ix['IPP-Coal'].capacity
-    gas_capacity = production.ix['LNG'].capacity + production.ix['IPP-LNG'].capacity
-    oil_capacity = production.ix['Oil'].capacity + production.ix['Diesel'].capacity
+    coal_capacity = production.loc['Coal'].capacity + production.loc['IPP-Coal'].capacity
+    gas_capacity = production.loc['LNG'].capacity + production.loc['IPP-LNG'].capacity
+    oil_capacity = production.loc['Oil'].capacity + production.loc['Diesel'].capacity
 
-    coal_production = production.ix['Coal'].output + production.ix['IPP-Coal'].output
-    gas_production = production.ix['LNG'].output + production.ix['IPP-LNG'].output
-    oil_production = production.ix['Oil'].output + production.ix['Diesel'].output
+    coal_production = production.loc['Coal'].output + production.loc['IPP-Coal'].output
+    gas_production = production.loc['LNG'].output + production.loc['IPP-LNG'].output
+    oil_production = production.loc['Oil'].output + production.loc['Diesel'].output
 
     # For storage, note that load will be negative, and generation positive.
     # We require the opposite
@@ -51,25 +53,25 @@ def fetch_production(zone_key='TW', session=None, target_datetime=None, logger=N
             'coal': coal_production,
             'gas': gas_production,
             'oil': oil_production,
-            'hydro': production.ix['Hydro'].output,
-            'nuclear': production.ix['Nuclear'].output,
-            'solar': production.ix['Solar'].output,
-            'wind': production.ix['Wind'].output,
-            'unknown': production.ix['Co-Gen'].output
+            'hydro': production.loc['Hydro'].output,
+            'nuclear': production.loc['Nuclear'].output,
+            'solar': production.loc['Solar'].output,
+            'wind': production.loc['Wind'].output,
+            'unknown': production.loc['Co-Gen'].output
         },
         'capacity': {
             'coal': coal_capacity,
             'gas': gas_capacity,
             'oil': oil_capacity,
-            'hydro': production.ix['Hydro'].capacity,
-            'hydro storage':production.ix['Pumping Gen'].capacity,
-            'nuclear': production.ix['Nuclear'].capacity,
-            'solar': production.ix['Solar'].capacity,
-            'wind': production.ix['Wind'].capacity,
-            'unknown': production.ix['Co-Gen'].capacity
+            'hydro': production.loc['Hydro'].capacity,
+            'hydro storage':production.loc['Pumping Gen'].capacity,
+            'nuclear': production.loc['Nuclear'].capacity,
+            'solar': production.loc['Solar'].capacity,
+            'wind': production.loc['Wind'].capacity,
+            'unknown': production.loc['Co-Gen'].capacity
         },
         'storage': {
-            'hydro': -1 * production.ix['Pumping Load'].output - production.ix['Pumping Gen'].output
+            'hydro': -1 * production.loc['Pumping Load'].output - production.loc['Pumping Gen'].output
         },
         'source': 'taipower.com.tw'
     }


Test patch: