Skip to content

Conversation

@uvchik
Copy link
Member

@uvchik uvchik commented Dec 9, 2019

Fix: #86

The read_csv() function of pandas read column names as strings. In a weather file the second level of the columns are the data heights. These heights should be of type integer.

With this PR these values are converted into integer values.

@uvchik uvchik self-assigned this Dec 9, 2019
@uvchik uvchik requested review from SabineHaas and birgits December 9, 2019 09:53
@uvchik uvchik added this to the v0.2.1 milestone Dec 9, 2019
# Convert data heights to integer. In some case they are strings.
weather_df.columns = pd.MultiIndex.from_arrays([
weather_df.columns.get_level_values(0),
weather_df.columns.get_level_values(1).astype(int)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why int and not float type? In the provided example the values are integers but that shouldn't be a rule, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion the inaccuracy of the model is higher than the decimal digit. Therefore I would always prefer integer.

But at them moment floats are allowed and it might be easier to allow floats than to forbid them and to explain why.

Comment on lines 443 to 445
weather_df.columns = pd.MultiIndex.from_arrays([
weather_df.columns.get_level_values(0),
weather_df.columns.get_level_values(1).astype(int)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe putting in a try statement and re-raising the error? In case someone passes in 80 m that cannot be converted to a number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the error message is quite clear. It also indicates the exact value that causes the problem. For us it would be more difficult to indicate the problematic value. We could add something like "The heights should be convertible to numeric." but it in my opinion the original message is better. We could also check the array and show all problematic values but I think it is not worth it.

@uvchik uvchik merged commit c4a5dbd into dev Jan 7, 2020
@uvchik uvchik deleted the features/allow-data-heigts-of-type-string branch January 7, 2020 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow heights in modelchains weather_df multiindex to be strings

4 participants