Skip to content

Commit

Permalink
Merge 249cf14 into 0fbe0f9
Browse files Browse the repository at this point in the history
  • Loading branch information
aloukina committed Apr 23, 2020
2 parents 0fbe0f9 + 249cf14 commit 31293c2
Show file tree
Hide file tree
Showing 859 changed files with 221,646 additions and 343,087 deletions.
43 changes: 8 additions & 35 deletions rsmtool/comparer.py
Expand Up @@ -123,32 +123,15 @@ def _modify_eval_columns_to_ensure_version_compatibilty(df,
smd_name = 'SMD'

# previously, the QWK metric used `trim_round` scores; now, we use just `trim` scores;
# to ensure backward compatibility, we check whether `trim_round` scores were used and
# if so, we update the rename dictionary and column lists accordingly
# We check whether `trim_round` scores were used and
# raise an error if this is the case
if any(col.endswith('trim_round') for col in df if col.startswith('wtkappa')):

# replace the `wtkappa_*_trim` with `wtkappa_*_trim_round`
rename_dict_new = {(key.replace('_trim', '_trim_round')
if key.startswith('wtkappa') else key):
(val.replace("(b)", "(br)")
if val.startswith('QWK') else val)
for key, val in rename_dict_new.items()}

# replace the `wtkappa_*_trim` with `wtkappa_*_trim_round`
existing_eval_cols_new = [col.replace('_trim', '_trim_round')
if col.startswith('wtkappa') else col
for col in existing_eval_cols_new]

# replace the `QWK(b)` with `QWK(br)`
short_metrics_list_new = [col.replace("(b)", "(br)")
if col.startswith('QWK') else col
for col in short_metrics_list_new]

if raise_warnings:
warnings.warn("Please note that newer versions of RSMTool (7.0 or greater) use only the trimmed "
"scores for weighted kappa calculations. Comparisons with experiments using "
"`trim_round` for weighted kappa calculations will be deprecated in the next "
"major release.", category=DeprecationWarning)
raise ValueError("Please note that newer versions of RSMTool (7.0 or greater) use only "
" the trimmed scores for weighted kappa calculations. At least one "
"of your experiments was created "
"using an older version of RSMTool and uses trim_round for "
"`trim_round` for weighted kappa calculations. Please re-run "
"the experiments with the recent version of RSMTool.")

# we check if DSM was calculated (which is what we expect for subgroup evals),
# and if so, we update the rename dictionary and column lists accordingly; we
Expand Down Expand Up @@ -476,16 +459,6 @@ def load_rsmtool_output(self, filedir, figdir, experiment_id, prefix, groups_eva
short_metrics_list,
raise_warnings=False)

# if `SMD` is being used, rather than `DSM`, we print a note for the user; we don't
# want to go so far as to raise a warning, but we do want to give the user some info
if smd_name == 'SMD':
warnings.warn("The subgroup evaluations in `{}` use 'SMD'. Please note "
"that newer versions of RSMTool (7.0 or greater) use 'DSM' with subgroup "
"evaluations. For additional details on how these metrics "
"differ, see the RSMTool documentation. Comparisons with experiments "
"using SMD for subgroup calculations will be deprecated in the next major "
"release.".format(group_eval_file), category=DeprecationWarning)

df_eval = df_eval[existing_eval_cols_new]
df_eval = df_eval.rename(columns=rename_dict_new)
files['df_eval_by_{}'.format(group)] = df_eval[short_metrics_list_new]
Expand Down
215 changes: 2 additions & 213 deletions rsmtool/configuration_parser.py
Expand Up @@ -32,8 +32,6 @@
CHECK_FIELDS,
LIST_FIELDS,
BOOLEAN_FIELDS,
MODEL_NAME_MAPPING,
FIELD_NAME_MAPPING,
ID_FIELDS)

from .utils.files import parse_json_with_comments
Expand All @@ -45,49 +43,6 @@
default_feature_sign)


def deprecated_positional_argument():
"""
This decorator allows the Configuration class to:
(a) accept the old method of specifying the now-deprecated ``filepath`` positional argument,
(b) accept the new method of specifying ``configdir`` and ``filename`` keyword arguments, but
(c) disallow using the old and the new methods in the same call
Adapted from: https://stackoverflow.com/a/49802489
"""
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
# if we received two positional arguments
if len(args) > 2:
# if we also received a keyword argument for filepath
# or configdir, raise an error
if 'filename' in kwargs:
raise ValueError("Cannot specify both the deprecated filepath "
"positional argument and the new-style filename "
"keyword argument.")
if 'configdir' in kwargs:
raise ValueError("Cannot specify both the deprecated filepath "
"positional argument and the new-style configdir "
"keyword argument.")
# raise deprecation warning
warnings.warn("The filepath positional argument is deprecated and "
" will be removed in v8.0. Use the ``configdir`` and "
"``filename`` keyword arguments instead.",
DeprecationWarning)

# split filepath into
# configdir and filename
filepath = args[-1]
kwargs['filename'] = Path(filepath).name
kwargs['configdir'] = Path(filepath).resolve().parent
# remove filepath from positional arguments
args = args[:-1]
return f(*args, **kwargs)
return wrapper
return decorator


def configure(context, config_file_or_obj_or_dict):
"""
Get the configuration for ``context`` from the input
Expand Down Expand Up @@ -166,7 +121,6 @@ class Configuration:
parameters.
"""

@deprecated_positional_argument()
def __init__(self,
configdict,
*,
Expand Down Expand Up @@ -195,8 +149,7 @@ def __init__(self,
filename : str, optional, keyword-only
The name of the configuration file.
The file must be stored in configdir.
This argument is not used in RSMTool and only added for
backwards compatibility for the deprecated `filepath` attribute.
This argument is currently not used in RSMTool.
Defaults to None.
context : {'rsmtool', 'rsmeval', 'rsmcompare',
'rsmpredict', 'rsmsummarize'}
Expand Down Expand Up @@ -312,61 +265,6 @@ def __iter__(self):
for key in self.keys():
yield key

@property
def filepath(self):
"""
Get file path to the configuration file.
.. deprecated:: 8.0
``filepath`` will be removed in RSMTool v8.0. Use ``configdir`` and
``filename`` instead.
Returns
-------
filepath : str
The path for the config file.
"""

# raise a deprecation warning first
warnings.warn("The `filepath` attribute of the Configuration "
"object will be removed in RSMTool v8.0."
"Use the `configdir` and `filename` attributes "
"if you need the full path to the "
"configuration file", DeprecationWarning)

# then compute the deprecated attribute if we can
if not self._filename:
raise AttributeError('The `filepath` attribute is not defined '
'for this Configuration object.')
else:
filepath = self._configdir / self._filename
return str(filepath)

@filepath.setter
def filepath(self, new_path):
"""
Set a new file path to configuration file.
.. deprecated:: 8.0
``filepath`` will be removed in RSMTool v8.0. Use ``configdir`` and
``filename`` instead.
Parameters
----------
new_path : str
A new file path for the Configuration object.
"""
warnings.warn("The `filepath` attribute of the Configuration "
"object will be removed in RSMTool 8.0 "
"use `configdir` and `filename` if you "
"need to set a new path to the "
"configuration file", DeprecationWarning)
new_filename = Path(new_path).name
new_configdir = Path(new_path).resolve().parent
self._filename = new_filename
self._configdir = new_configdir

@property
def configdir(self):
"""
Expand Down Expand Up @@ -687,24 +585,6 @@ def check_flag_column(self,
model_eval))
return new_filter_dict

def get_trim_min_max(self):
"""
This function is kept for backwards compatibility.
It is now replaced by get_trim_min_max_tolerance
and will be deprecated in future versions.
Returns
-------
spec_trim_min : float
Specified trim min value
spec_trim_max : float
Specified trim max value
"""
logging.warning("get_trim_min_max method has been replaced by "
"get_trim_min_max_tolerance() and will "
"not be supported in future releases.")
(trim_min, trim_max, tolerance) = self.get_trim_min_max_tolerance()
return (trim_min, trim_max)

def get_trim_min_max_tolerance(self):
"""
Expand Down Expand Up @@ -928,61 +808,6 @@ def _parse_json_file(self, filepath):

return configdict

def _parse_cfg_file(self, filepath):
"""
A private method to parse INI-style configuration files and
return a Python dictionary.
Parameters
----------
filepath : pathlib.Path
A ``pathlib.Path`` object containing the CFG configuration filepath.
Returns
-------
configdict : dict
A Python dictionary containing the parameters from the
CFG configuration file.
Raises
------
ValueError
If the configuration file could not be read or parsed.
"""
# Get the `ConfigParser` object
py_config_parser = ConfigParser()

# Try to read main configuration file.
try:
py_config_parser.read(filepath)
except Exception as error:
raise ValueError('Main configuration file '
'could not be read: {}'.format(error))

configdict = {}

# Loop through all sections of the ConfigParser
# object and add items to the dictionary
for section in py_config_parser.sections():
for name, value in py_config_parser.items(section):

# Check if the key already exists in the config dictionary.
# If it does, skip it and log a warning.
if name in configdict:
logging.warning('There are duplicate keys for `{}`'
'in the configuration file. Only '
'the first instance will be '
'included.'.format(name))
continue

# Otherwise, safe convert the value
# and add it to the dictionary.
else:
value = self._fix_json(value)
value = yaml.safe_load(value)
configdict[name] = value

return configdict

def parse(self, context='rsmtool'):
"""
Expand Down Expand Up @@ -1051,19 +876,7 @@ def normalize_config(cls, config):

for field_name in config:

if field_name in FIELD_NAME_MAPPING:
norm_field_name = FIELD_NAME_MAPPING[field_name]
warnings.warn("""The field name "{}" is deprecated """
"""and will be removed in a future """
"""release, please use the """
"""new field name "{}" """
"""instead.""".format(field_name,
norm_field_name),
category=DeprecationWarning)
else:
norm_field_name = field_name

new_config[norm_field_name] = config[field_name]
new_config[field_name] = config[field_name]

# Convert old values for prediction scaling:
if 'use_scaled_predictions' in new_config:
Expand All @@ -1076,30 +889,6 @@ def normalize_config(cls, config):
"to specify prediction scaling:\n "
"'use_scaled_predictions': true/false")

# Convert old model names to new ones, if we have them
if 'model' in new_config:
model_name = new_config['model']

if model_name == 'empWtDropNeg':

# If someone is using `empWtDropNeg`, we tell them that it is
# no longer available and they should be using NNLR instead.
logging.error("""The model name "empWtDropNeg" is """
"""no longer available, please use the """
"""equivalent model "NNLR" instead.""")

# Otherwise, just raise a deprecation warning if they are using
# an old model name
elif model_name in MODEL_NAME_MAPPING:
norm_model_name = MODEL_NAME_MAPPING[model_name]
warnings.warn("""The model name "{}" is deprecated """
"""and will be removed in a future """
"""release, please use the new model """
"""name "{}" instead.""".format(model_name,
norm_model_name),
category=DeprecationWarning)
new_config['model'] = norm_model_name

return new_config

@classmethod
Expand Down

0 comments on commit 31293c2

Please sign in to comment.