Skip to content

Commit b3bc68d

Browse files
authored
Feature/newer pythons (#71)
* refactor to support newer python versions and dependencies * update minimum python to 3.9
1 parent 376dc15 commit b3bc68d

16 files changed

+2511
-2090
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
env:
1414
OS: ${{ matrix.os }}
15-
PYTHON: '3.7'
15+
PYTHON: '3.9'
1616

1717
steps:
1818

@@ -21,7 +21,7 @@ jobs:
2121
- name: Set up Python
2222
uses: actions/setup-python@master
2323
with:
24-
python-version: 3.7
24+
python-version: 3.9
2525

2626
- name: Install dependencies
2727
run: |
@@ -38,4 +38,4 @@ jobs:
3838
uses: codecov/codecov-action@v1
3939
with:
4040
file: ./coverage.xml
41-
fail_ci_if_error: true
41+
fail_ci_if_error: false

diyepw/_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import logging
22
import os
33
import sys
4-
import pkg_resources
4+
import importlib_resources
55
from datetime import datetime
66

77
_LOG_LEVEL = logging.INFO
88

9-
log_dir = pkg_resources.resource_filename("diyepw", "log")
9+
log_dir = importlib_resources.files("diyepw") / "log"
1010
if not os.path.exists(log_dir): # pragma: no cover
1111
os.mkdir(log_dir)
1212

diyepw/analyze_noaa_isd_lite_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def analyze_noaa_isd_lite_file(
2727
"""
2828
# Read the file into a Pandas dataframe.
2929
df = pd.read_csv(file,
30-
delim_whitespace=True,
30+
sep='\\s+',
3131
header=None,
3232
compression=compression,
3333
names=["Year", "Month", "Day", "Hour", "Air_Temperature",
@@ -68,7 +68,7 @@ def _get_max_missing_rows_from_hourly_dataframe(df: pd.DataFrame, timestamp_col_
6868
:return: The size of the longest sequence of missing timestamps from the Dataframe `df`
6969
"""
7070
# Create series of continuous timestamp values for that year
71-
all_timestamps = pd.date_range(df[timestamp_col_name].iloc[0], periods=8760, freq='H')
71+
all_timestamps = pd.date_range(df[timestamp_col_name].iloc[0], periods=8760, freq='h')
7272

7373
# Merge to one dataframe containing all continuous timestamp values.
7474
all_times = pd.DataFrame(all_timestamps, columns=['all_timestamps'])

diyepw/create_amy_epw_file.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pandas as pd
88
import numpy as np
99
import os
10-
import pkg_resources
10+
import importlib_resources
1111
from typing import Tuple
1212
from calendar import isleap
1313

@@ -85,7 +85,7 @@ def create_amy_epw_file(
8585
amy_file_path, amy_next_year_file_path = amy_files
8686
else:
8787
if amy_dir is None:
88-
amy_dir = pkg_resources.resource_filename("diyepw", "data/noaa_isd_lite_files")
88+
amy_dir = importlib_resources.files("diyepw") / "data/noaa_isd_lite_files"
8989
_logger.info(f"No amy_dir was specified - downloaded AMY files will be stored in the default location at {amy_dir}")
9090

9191
amy_file_path = get_noaa_isd_lite_file(wmo_index, year, output_dir=amy_dir, allow_downloads=allow_downloads)
@@ -110,7 +110,7 @@ def create_amy_epw_file(
110110
new_row_vals = [1982, 2, 29, hour, 0]
111111
new_row_vals.extend(np.repeat(np.nan, len(col_names) - len(new_row_vals)))
112112
new_row = pd.DataFrame([new_row_vals], columns=col_names)
113-
tmy.observations = tmy.observations.append(new_row)
113+
tmy.observations = pd.concat([tmy.observations, new_row], ignore_index=True)
114114

115115
# We sort by month, day and hour. We do *not* sort by year, because the year column doesn't matter and because
116116
# it is in any case not consistent throughout a TMY data set
@@ -140,15 +140,15 @@ def create_amy_epw_file(
140140
# to handle the largest possible timezone shift) of the subsequent year - the subsequent year's data will be
141141
# used to populate the last hours of the year because of the time shift that we perform, which moves the first
142142
# hours of January 1 into the final hours of December 31.
143-
amy_df = pd.read_csv(amy_file_path, delim_whitespace=True, header=None)
144-
amy_next_year_df = pd.read_csv(amy_next_year_file_path, delim_whitespace=True, header=None, nrows=23)
143+
amy_df = pd.read_csv(amy_file_path, sep='\\s+', header=None)
144+
amy_next_year_df = pd.read_csv(amy_next_year_file_path, sep='\\s+', header=None, nrows=23)
145145
amy_df = pd.concat([amy_df, amy_next_year_df]).reset_index(drop=True)
146146

147147
amy_df = _set_noaa_df_columns(amy_df)
148148
amy_df = _create_timestamp_index_for_noaa_df(amy_df)
149149

150150
# Shift the timestamp (index) to match the time zone of the WMO station.
151-
amy_df = amy_df.shift(periods= tmy.timezone_gmt_offset, freq='H')
151+
amy_df = amy_df.shift(periods= tmy.timezone_gmt_offset, freq='h')
152152

153153
# Remove time steps that aren't applicable to the year of interest
154154
amy_df = _map_noaa_df_to_year(amy_df, year)
@@ -237,7 +237,7 @@ def _map_noaa_df_to_year(df, year):
237237
The assumption of this function is that the dataframe ranges from the beginning of the year to some
238238
"""
239239
# Create series of continuous timestamp values for that year
240-
all_timestamps = pd.date_range(str(year) + '-01-01 00:00:00', str(year) + '-12-31 23:00:00', freq='H')
240+
all_timestamps = pd.date_range(str(year) + '-01-01 00:00:00', str(year) + '-12-31 23:00:00', freq='h')
241241
all_timestamps = pd.DataFrame(all_timestamps, columns=['timestamp'])
242242

243243
# Merge to one dataframe containing all continuous timestamp values.
@@ -352,13 +352,13 @@ def get_indices_to_replace(df, col_name):
352352
replacement_value_index += imputation_step
353353

354354
# Take the mean of the values pulled. Will ignore NaNs.
355-
df[col_name][index_to_impute] = pd.Series(replacement_values, dtype=np.float64).mean()
355+
df.loc[index_to_impute, col_name] = pd.Series(replacement_values, dtype=np.float64).mean()
356356

357357
# Perform interpolation on any remaining missing values. At this point we know that there are no
358358
# sequences larger than the max permitted for interpolation, because they would have been imputed
359359
# or caused an exception (if larger than the imputation limit), so we can just call interpolate()
360360
# on anything that is still missing.
361-
df[col_name].interpolate(inplace=True)
361+
df[col_name] = df[col_name].interpolate()
362362

363363
def _split_list_into_contiguous_segments(l:list, step):
364364
"""
@@ -417,4 +417,4 @@ def _convert_sea_level_pressure_to_station_pressure(Pa, h_m) -> object:
417417
# convert from inHg to Pa
418418
Pstn = Pstn_inHg * 3386.389
419419

420-
return Pstn
420+
return Pstn

0 commit comments

Comments
 (0)