oemof / demandlib

Creating heat and power demand profiles from annual values.
https://oemof.org
MIT License
56 stars 38 forks source link

Error in HeatBuilding example of demandlib #3

Closed simnh closed 7 years ago

simnh commented 7 years ago

Great, thanks for the first release of the demandlib. I tried to run the heat_demand example for the example directory and got the following error:

Traceback (most recent call last):
  File "/home/simon/uni/repos/demandlib/examples/heat_demand_example.py", line 37, in <module>
    name='EFH').get_bdew_profile()
  File "/home/simon/uni/repos/demandlib/demandlib/bdew.py", line 328, in get_bdew_profile
    how="geometric_series")
  File "/home/simon/uni/repos/demandlib/demandlib/bdew.py", line 207, in weighted_temperature
    temperature = self.df["temperature"].resample('D').mean().reindex(
AttributeError: 'numpy.float64' object has no attribute 'reindex'
uvchik commented 7 years ago

Latest commit? I cannot reproduce the error. Maybe there is something wrong with the temperature file.

This is my output of self.df["temperature"]:

2010-01-01 00:00:00   -0.2
2010-01-01 01:00:00   -0.1
2010-01-01 02:00:00    0.1
2010-01-01 03:00:00   -0.1
2010-01-01 04:00:00   -0.1
2010-01-01 05:00:00   -0.1
2010-01-01 06:00:00    0.1
                      ... 
2010-12-31 17:00:00    0.2
2010-12-31 18:00:00    0.3
2010-12-31 19:00:00    0.2
2010-12-31 20:00:00    0.0
2010-12-31 21:00:00   -0.3
2010-12-31 22:00:00   -0.4
2010-12-31 23:00:00   -0.4
Freq: H, Name: temperature, dtype: float64
simnh commented 7 years ago

I just pulled the repo, and work on the latest commit 757e15c5c796988dfba082d674016742de09dfda

uvchik commented 7 years ago

Can you post the output of print(self.df["temperature"]) right before the error. Does it look similar to my output above?

The error indicates that the result of self.df["temperature"].resample('D').mean() is not a pandas.Series but a float object. As I think resample and mean should work the same, I think that the temperature in your case might not be correct. Or it has something to do with your pandas installation. I tried it with 0.19 and 0.18.

simnh commented 7 years ago

I am confused by this line:

  temperature = self.df["temperature"].resample('D').mean().reindex(
            self.df.index).fillna(method="ffill")

The reindexing fails i guess, because mean() is called on the series, which results in a scalar, which can not be reindexed.

If the daily mean temperature is needed i guess this would make more sense (which works for me):

  temperature = self.df["temperature"].resample('D', how='mean').reindex(
            self.df.index).fillna(method="ffill")
simnh commented 7 years ago

If you agree I would push a hotfix for the version. But I am confused, why you cannnot reproduce the error...

uvchik commented 7 years ago

According to my comment above:

Or it has something to do with your pandas installation. I tried it with 0.19 and 0.18.

As I read your suggestion to fix the bug I found out that the error is caused by a changed API of the resample method since 0.18. I could not reproduce it because I use pandas 0.18 and 0.19.

Old API (until 0.17):

resample(..., how='sum')

New API (since 0.18):

resample(...).sum()
resample(...).agg('sum')

See: http://pandas.pydata.org/pandas-docs/version/0.18.0/whatsnew.html#resample-api

I did change the requirements in the setup.py so that at least pandas 0.18 has to be installed.

simnh commented 7 years ago

Ok fixed it for me....I liked the old Api better....

uvchik commented 7 years ago

The new one is more flexible, because you can even pass your own function.