ods-tools 3.2.3__tar.gz → 3.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ods_tools-3.2.3 → ods_tools-3.2.4}/PKG-INFO +1 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/__init__.py +1 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/__init__.py +2 -2
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/common.py +14 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/exposure.py +2 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/oed_schema.py +20 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/source.py +4 -9
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/validator.py +15 -10
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools.egg-info/PKG-INFO +1 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/setup.py +1 -1
- {ods_tools-3.2.3 → ods_tools-3.2.4}/README.md +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/data/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/main.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/config.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/connector/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/connector/base.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/connector/csv.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/controller.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/data/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/errors.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/files/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/files/csv.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/files/yaml.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/log.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/mapping/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/mapping/base.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/mapping/errors.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/mapping/file.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/notset.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/runner/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/runner/base.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/runner/pandas.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/transformers/__init__.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/transformers/errors.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/transformers/grammar.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/transformers/transform.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/transformers/transform_utils.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/validator_base.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/odtf/validator_pandas.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/forex.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools/oed/setting_schema.py +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools.egg-info/SOURCES.txt +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools.egg-info/dependency_links.txt +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools.egg-info/entry_points.txt +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools.egg-info/requires.txt +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/ods_tools.egg-info/top_level.txt +0 -0
- {ods_tools-3.2.3 → ods_tools-3.2.4}/setup.cfg +0 -0
|
@@ -5,7 +5,7 @@ from .source import OedSource
|
|
|
5
5
|
from .common import (
|
|
6
6
|
OdsException, PANDAS_COMPRESSION_MAP, PANDAS_DEFAULT_NULL_VALUES, USUAL_FILE_NAME, OED_TYPE_TO_NAME,
|
|
7
7
|
OED_NAME_TO_TYPE, OED_IDENTIFIER_FIELDS, VALIDATOR_ON_ERROR_ACTION, DEFAULT_VALIDATION_CONFIG, OED_PERIL_COLUMNS, fill_empty,
|
|
8
|
-
UnknownColumnSaveOption, BLANK_VALUES
|
|
8
|
+
UnknownColumnSaveOption, BLANK_VALUES, is_empty
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
|
|
@@ -13,5 +13,5 @@ __all__ = [
|
|
|
13
13
|
'OedExposure', 'OedSchema', 'OedSource', 'ModelSettingSchema', 'AnalysisSettingSchema',
|
|
14
14
|
'OdsException', 'PANDAS_COMPRESSION_MAP', 'PANDAS_DEFAULT_NULL_VALUES', 'USUAL_FILE_NAME', 'OED_TYPE_TO_NAME',
|
|
15
15
|
'OED_NAME_TO_TYPE', 'OED_IDENTIFIER_FIELDS', 'VALIDATOR_ON_ERROR_ACTION', 'DEFAULT_VALIDATION_CONFIG', 'OED_PERIL_COLUMNS', 'fill_empty',
|
|
16
|
-
'UnknownColumnSaveOption', 'BLANK_VALUES'
|
|
16
|
+
'UnknownColumnSaveOption', 'BLANK_VALUES', 'is_empty'
|
|
17
17
|
]
|
|
@@ -143,6 +143,19 @@ OED_PERIL_COLUMNS = ['AccPeril', 'PolPerilsCovered', 'PolPeril', 'CondPeril', 'L
|
|
|
143
143
|
|
|
144
144
|
BLANK_VALUES = {np.nan, '', None, pd.NA, pd.NaT}
|
|
145
145
|
|
|
146
|
+
dtype_to_python = {
|
|
147
|
+
'Int8': int,
|
|
148
|
+
'Int32': int,
|
|
149
|
+
'Int64': int,
|
|
150
|
+
'bytes': lambda x: bytes(x, 'utf-8'),
|
|
151
|
+
'float64': float,
|
|
152
|
+
'category': str
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def is_empty(df, columns):
|
|
157
|
+
return (df[columns].isnull()) | (df[columns] == '')
|
|
158
|
+
|
|
146
159
|
|
|
147
160
|
def fill_empty(df, columns, value):
|
|
148
161
|
if isinstance(columns, str):
|
|
@@ -151,7 +164,7 @@ def fill_empty(df, columns, value):
|
|
|
151
164
|
dtype = getattr(df[column], "dtypes", getattr(df[column], "dtype", None))
|
|
152
165
|
if dtype.name == 'category' and value not in {None, np.nan}.union(df[column].cat.categories):
|
|
153
166
|
df[column] = df[column].cat.add_categories(value)
|
|
154
|
-
df.loc[df
|
|
167
|
+
df.loc[is_empty(df, column), column] = value
|
|
155
168
|
|
|
156
169
|
|
|
157
170
|
class UnknownColumnSaveOption(Enum):
|
|
@@ -8,6 +8,7 @@ This package manage:
|
|
|
8
8
|
import json
|
|
9
9
|
from copy import deepcopy
|
|
10
10
|
import logging
|
|
11
|
+
import numpy as np
|
|
11
12
|
from packaging import version
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
|
|
@@ -80,7 +81,7 @@ class OedExposure:
|
|
|
80
81
|
if column not in df.columns or not values:
|
|
81
82
|
return df
|
|
82
83
|
|
|
83
|
-
return df[df[column]
|
|
84
|
+
return df[np.isin(df[column], values)]
|
|
84
85
|
return fn
|
|
85
86
|
|
|
86
87
|
loc_filters = [
|
|
@@ -4,7 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
import numba as nb
|
|
5
5
|
import numpy as np
|
|
6
6
|
|
|
7
|
-
from .common import OdsException, BLANK_VALUES, cached_property
|
|
7
|
+
from .common import OdsException, BLANK_VALUES, cached_property, dtype_to_python
|
|
8
8
|
|
|
9
9
|
ENV_ODS_SCHEMA_PATH = os.getenv('ODS_SCHEMA_PATH')
|
|
10
10
|
|
|
@@ -139,6 +139,25 @@ class OedSchema:
|
|
|
139
139
|
return jit_peril_filtering(peril_ids.to_numpy().astype('str'), peril_filters.to_numpy().astype('str'),
|
|
140
140
|
self.nb_peril_groups_dict if include_sub_group else self.nb_perils_dict)
|
|
141
141
|
|
|
142
|
+
@staticmethod
|
|
143
|
+
def get_default_from_ods_fields(ods_fields, field_name):
|
|
144
|
+
field_info = ods_fields.get(field_name.lower())
|
|
145
|
+
if field_info is None:
|
|
146
|
+
return ''
|
|
147
|
+
if field_info['pd_dtype'] == 'category':
|
|
148
|
+
if field_info['Default'] != 'n/a':
|
|
149
|
+
return field_info['Default']
|
|
150
|
+
else:
|
|
151
|
+
return ''
|
|
152
|
+
else:
|
|
153
|
+
if field_info['Default'] != 'n/a':
|
|
154
|
+
return dtype_to_python[field_info['pd_dtype']](field_info['Default'])
|
|
155
|
+
else:
|
|
156
|
+
return np.nan
|
|
157
|
+
|
|
158
|
+
def get_default(self, field_name, oed_type='null'):
|
|
159
|
+
return self.get_default_from_ods_fields(self.schema['input_fields'][oed_type], field_name)
|
|
160
|
+
|
|
142
161
|
@staticmethod
|
|
143
162
|
def to_universal_field_name(column: str):
|
|
144
163
|
"""
|
|
@@ -7,8 +7,8 @@ from oasis_data_manager.df_reader.config import get_df_reader
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from chardet.universaldetector import UniversalDetector
|
|
9
9
|
|
|
10
|
-
from .common import (OED_TYPE_TO_NAME, OdsException, PANDAS_COMPRESSION_MAP, PANDAS_DEFAULT_NULL_VALUES, is_relative,
|
|
11
|
-
UnknownColumnSaveOption, cached_property)
|
|
10
|
+
from .common import (OED_TYPE_TO_NAME, OdsException, PANDAS_COMPRESSION_MAP, PANDAS_DEFAULT_NULL_VALUES, is_relative, fill_empty,
|
|
11
|
+
UnknownColumnSaveOption, cached_property, is_empty)
|
|
12
12
|
from .forex import convert_currency
|
|
13
13
|
from .oed_schema import OedSchema
|
|
14
14
|
|
|
@@ -282,7 +282,7 @@ class OedSource:
|
|
|
282
282
|
if oed_df[column].dtype.name == 'category' and '' not in oed_df[column].dtype.categories:
|
|
283
283
|
oed_df[column] = oed_df[column].cat.add_categories('')
|
|
284
284
|
oed_df[column] = oed_df[column] # make a copy f the col in case it is read_only
|
|
285
|
-
oed_df.loc[oed_df
|
|
285
|
+
oed_df.loc[is_empty(oed_df, column), column] = ''
|
|
286
286
|
elif pd_dtype[column].startswith('Int'):
|
|
287
287
|
to_tmp_dtype[column] = 'float'
|
|
288
288
|
|
|
@@ -302,12 +302,7 @@ class OedSource:
|
|
|
302
302
|
"""
|
|
303
303
|
# set default values
|
|
304
304
|
for col, field_info in column_to_field.items():
|
|
305
|
-
|
|
306
|
-
and field_info['Default'] != 'n/a'
|
|
307
|
-
and (df[col].isna().any() or (field_info['pd_dtype'] == 'category' and df[col].isnull().any()))):
|
|
308
|
-
fill_empty(df, col, df[col].dtype.type(field_info['Default']))
|
|
309
|
-
elif df[col].dtype.name == 'category':
|
|
310
|
-
fill_empty(df, col, '')
|
|
305
|
+
fill_empty(df, col, OedSchema.get_default_from_ods_fields(ods_fields, col))
|
|
311
306
|
|
|
312
307
|
# add required columns that allow blank values if missing
|
|
313
308
|
present_field = set(field_info['Input Field Name'] for field_info in column_to_field.values())
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import functools
|
|
2
2
|
import json
|
|
3
|
+
import numpy as np
|
|
3
4
|
import logging
|
|
4
5
|
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from collections.abc import Iterable
|
|
7
8
|
|
|
8
9
|
from .common import (OdsException, OED_PERIL_COLUMNS, OED_IDENTIFIER_FIELDS, DEFAULT_VALIDATION_CONFIG,
|
|
9
|
-
VALIDATOR_ON_ERROR_ACTION, BLANK_VALUES)
|
|
10
|
+
VALIDATOR_ON_ERROR_ACTION, BLANK_VALUES, is_empty)
|
|
10
11
|
from .oed_schema import OedSchema
|
|
11
12
|
|
|
12
13
|
logger = logging.getLogger(__name__)
|
|
@@ -134,7 +135,7 @@ class Validator:
|
|
|
134
135
|
columns = [columns]
|
|
135
136
|
for column in columns:
|
|
136
137
|
if field_info.get("Allow blanks?").upper() == 'NO':
|
|
137
|
-
missing_value_df = oed_source.dataframe[oed_source.dataframe
|
|
138
|
+
missing_value_df = oed_source.dataframe[is_empty(oed_source.dataframe, column)]
|
|
138
139
|
if not missing_value_df.empty:
|
|
139
140
|
invalid_data.append({'name': oed_source.oed_name, 'source': oed_source.current_source,
|
|
140
141
|
'msg': f"column '{column}' has missing values in \n"
|
|
@@ -222,8 +223,9 @@ class Validator:
|
|
|
222
223
|
if occupancy_code_column is None:
|
|
223
224
|
continue
|
|
224
225
|
identifier_field = self.identifier_field_maps[oed_source]
|
|
225
|
-
invalid_occupancy_code = oed_source.dataframe[~oed_source.dataframe[occupancy_code_column].astype(str)
|
|
226
|
-
|
|
226
|
+
invalid_occupancy_code = oed_source.dataframe[~(np.isin(oed_source.dataframe[occupancy_code_column].astype(str),
|
|
227
|
+
list(self.exposure.oed_schema.schema['occupancy']))
|
|
228
|
+
| is_empty(oed_source.dataframe, occupancy_code_column))]
|
|
227
229
|
if not invalid_occupancy_code.empty:
|
|
228
230
|
invalid_data.append({'name': oed_source.oed_name, 'source': oed_source.current_source,
|
|
229
231
|
'msg': f"invalid OccupancyCode.\n"
|
|
@@ -242,8 +244,9 @@ class Validator:
|
|
|
242
244
|
if construction_code_column is None:
|
|
243
245
|
continue
|
|
244
246
|
identifier_field = self.identifier_field_maps[oed_source]
|
|
245
|
-
invalid_construction_code = oed_source.dataframe[~oed_source.dataframe[construction_code_column].astype(str)
|
|
246
|
-
|
|
247
|
+
invalid_construction_code = oed_source.dataframe[~(np.isin(oed_source.dataframe[construction_code_column].astype(str),
|
|
248
|
+
list(self.exposure.oed_schema.schema['construction']))
|
|
249
|
+
| is_empty(oed_source.dataframe, construction_code_column))]
|
|
247
250
|
if not invalid_construction_code.empty:
|
|
248
251
|
invalid_data.append({'name': oed_source.oed_name, 'source': oed_source.current_source,
|
|
249
252
|
'msg': f"invalid ConstructionCode.\n"
|
|
@@ -265,8 +268,9 @@ class Validator:
|
|
|
265
268
|
identifier_field = self.identifier_field_maps[oed_source]
|
|
266
269
|
area_code_column = self.field_to_column_maps[oed_source].get('AreaCode')
|
|
267
270
|
if area_code_column is not None:
|
|
268
|
-
country_only_df = oed_source.dataframe[oed_source.dataframe
|
|
269
|
-
country_area_df = oed_source.dataframe[~oed_source.dataframe
|
|
271
|
+
country_only_df = oed_source.dataframe[is_empty(oed_source.dataframe, area_code_column)]
|
|
272
|
+
country_area_df = oed_source.dataframe[~is_empty(oed_source.dataframe, area_code_column)]
|
|
273
|
+
|
|
270
274
|
invalid_country_area = (country_area_df[
|
|
271
275
|
~(country_area_df[[country_code_column, area_code_column]]
|
|
272
276
|
.apply(tuple, axis=1)
|
|
@@ -279,8 +283,9 @@ class Validator:
|
|
|
279
283
|
f"{invalid_country_area[identifier_field + [country_code_column, area_code_column]]}"})
|
|
280
284
|
else:
|
|
281
285
|
country_only_df = oed_source.dataframe
|
|
282
|
-
invalid_country = (country_only_df[~country_only_df[country_code_column]
|
|
283
|
-
|
|
286
|
+
invalid_country = (country_only_df[~(np.isin(country_only_df[country_code_column],
|
|
287
|
+
list(self.exposure.oed_schema.schema['country']))
|
|
288
|
+
| is_empty(country_only_df, country_code_column))])
|
|
284
289
|
if not invalid_country.empty:
|
|
285
290
|
invalid_data.append({'name': oed_source.oed_name, 'source': oed_source.current_source,
|
|
286
291
|
'msg': f"invalid CountryCode.\n"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|