Skip to content

Commit

Permalink
Fix - Fixed get_loc deprecation warning using now get_indexer pandas …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
davidusb-geek committed Apr 21, 2022
1 parent 5dd6632 commit e8f5568
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.9] - 2022-04-21
### Fix
- Fixed get_loc deprecation warning using now get_indexer pandas method. Improved selection of closest index.

## [0.2.8] - 2022-04-18
### Fix
- Fixed if sentence to correctly use the supervisor API for publish data.
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'David HERNANDEZ'

# The full version, including alpha/beta/rc tags
release = '0.2.8'
release = '0.2.9'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='emhass', # Required
version='0.2.8', # Required
version='0.2.9', # Required
description='An Energy Management System for Home Assistant', # Optional
long_description=long_description, # Optional
long_description_content_type='text/markdown', # Optional (see note above)
Expand Down
8 changes: 3 additions & 5 deletions src/emhass/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,9 @@ def publish_data(input_data_dict: dict, logger: logging.Logger,
opt_res_dayahead.index.freq = input_data_dict['retrieve_hass_conf']['freq']
# Estimate the current index
now_precise = datetime.now(input_data_dict['retrieve_hass_conf']['time_zone']).replace(second=0, microsecond=0)
try:
idx_closest = opt_res_dayahead.index.get_loc(now_precise, method='ffill')
except Exception:
logger.warning("Problem finding DataFrame index, using nearest option as a backup")
idx_closest = opt_res_dayahead.index.get_loc(now_precise, method='nearest')
idx_closest = opt_res_dayahead.index.get_indexer([now_precise], method='ffill')[0]
if idx_closest == -1:
idx_closest = opt_res_dayahead.index.get_indexer([now_precise], method='nearest')[0]
# Publish PV forecast
input_data_dict['rh'].post_data(opt_res_dayahead['P_PV'], idx_closest,
'sensor.p_pv_forecast', "W", "PV Power Forecast")
Expand Down
10 changes: 10 additions & 0 deletions tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
import pathlib
import pickle
from datetime import datetime, timezone

from emhass.retrieve_hass import retrieve_hass
from emhass.optimization import optimization
Expand Down Expand Up @@ -55,6 +56,9 @@ def setUp(self):
self.days_list, self.costfun, root, logger)
self.df_input_data = self.fcst.get_load_cost_forecast(self.df_input_data)
self.df_input_data = self.fcst.get_prod_price_forecast(self.df_input_data)
self.input_data_dict = {
'retrieve_hass_conf': retrieve_hass_conf,
}

def test_perform_perfect_forecast_optim(self):
self.opt_res = self.opt.perform_perfect_forecast_optim(self.df_input_data)
Expand All @@ -72,6 +76,12 @@ def test_perform_dayahead_forecast_optim(self):
self.assertIsInstance(self.opt_res_dayahead.index, pd.core.indexes.datetimes.DatetimeIndex)
self.assertIsInstance(self.opt_res_dayahead.index.dtype, pd.core.dtypes.dtypes.DatetimeTZDtype)
self.assertTrue('cost_fun_'+self.costfun in self.opt_res_dayahead.columns)
# Testing estimation of the current index
now_precise = datetime.now(self.input_data_dict['retrieve_hass_conf']['time_zone']).replace(second=0, microsecond=0)
idx_closest = self.opt_res_dayahead.index.get_indexer([now_precise], method='ffill')[0]
self.assertTrue(idx_closest == -1)
idx_closest = self.opt_res_dayahead.index.get_indexer([now_precise], method='nearest')[0]
self.assertTrue(idx_closest == 0)

if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit e8f5568

Please sign in to comment.