Skip to content

Commit

Permalink
Merge pull request Trusted-AI#50 from IBM/prej-remov-compat-fix
Browse files Browse the repository at this point in the history
Python 2.7 compatibility fix
  • Loading branch information
michaelhind authored Nov 14, 2018
2 parents d1e0cba + 9a34701 commit 57135d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
import argparse
import os
import platform
import commands
try:
from commands import getoutput
except ImportError:
from subprocess import getoutput
import logging
import datetime
import pickle
Expand Down Expand Up @@ -263,13 +266,13 @@ def main(opt):
opt.sys_uname = platform.uname()
if platform.system() == 'Darwin':
opt.sys_info =\
commands.getoutput('system_profiler'
' -detailLevel mini SPHardwareDataType')\
getoutput('system_profiler'
' -detailLevel mini SPHardwareDataType')\
.split('\n')[4:-1]
elif platform.system() == 'FreeBSD':
opt.sys_info = commands.getoutput('sysctl hw').split('\n')
opt.sys_info = getoutput('sysctl hw').split('\n')
elif platform.system() == 'Linux':
opt.sys_info = commands.getoutput('cat /proc/cpuinfo').split('\n')
opt.sys_info = getoutput('cat /proc/cpuinfo').split('\n')

### suppress warnings in numerical computation
np.seterr(all='ignore')
Expand Down
13 changes: 8 additions & 5 deletions aif360/algorithms/inprocessing/kamfadm-2012ecmlpkdd/train_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@
import argparse
import os
import platform
import commands
try:
from commands import getoutput
except ImportError:
from subprocess import getoutput
import logging
import datetime
import pickle
Expand Down Expand Up @@ -304,13 +307,13 @@ def main(opt):
opt.sys_uname = platform.uname()
if platform.system() == 'Darwin':
opt.sys_info =\
commands.getoutput('system_profiler'
' -detailLevel mini SPHardwareDataType')\
getoutput('system_profiler'
' -detailLevel mini SPHardwareDataType')\
.split('\n')[4:-1]
elif platform.system() == 'FreeBSD':
opt.sys_info = commands.getoutput('sysctl hw').split('\n')
opt.sys_info = getoutput('sysctl hw').split('\n')
elif platform.system() == 'Linux':
opt.sys_info = commands.getoutput('cat /proc/cpuinfo').split('\n')
opt.sys_info = getoutput('cat /proc/cpuinfo').split('\n')

### suppress warnings in numerical computation
np.seterr(all='ignore')
Expand Down
22 changes: 12 additions & 10 deletions aif360/algorithms/inprocessing/prejudice_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- kamfadm-2012ecmlpkdd/train_lr.py
- kamfadm-2012ecmlpkdd/train_nb.py
* fixed typo in kamfadm-2012ecmlpkdd/fadm/lr/pr.py:244 (typeError -> TypeError)
* removed commands.py and instead use subprocess.getoutput if commands is
not available
Notes from fairness-comparison's KamishimaAlgorithm.py on changes made to
original Kamishima code.
Expand Down Expand Up @@ -186,11 +188,11 @@ def create_file_in_kamishima_format(df):
#ADDED FOLLOWING LINE to get absolute path of this file, i.e. KamishimaAlgorithm.py
k_path = os.path.dirname(os.path.abspath(__file__))
#changed paths in the calls below to (a) specify path of train_pr,predict_lr RELATIVE to this file, and (b) compute & use absolute path, and (c) replace python3 with python
subprocess.run(['python', os.path.join(k_path, 'kamfadm-2012ecmlpkdd', 'train_pr.py'),
'-e', str(eta_val),
'-i', train_name,
'-o', model_name,
'--quiet'])
subprocess.call(['python', os.path.join(k_path, 'kamfadm-2012ecmlpkdd', 'train_pr.py'),
'-e', str(eta_val),
'-i', train_name,
'-o', model_name,
'--quiet'])
os.unlink(train_name)
#os.unlink(model_name)

Expand Down Expand Up @@ -228,11 +230,11 @@ def create_file_in_kamishima_format(df):
#ADDED FOLLOWING LINE to get absolute path of this file, i.e. KamishimaAlgorithm.py
k_path = os.path.dirname(os.path.abspath(__file__))
#changed paths in the calls below to (a) specify path of train_pr,predict_lr RELATIVE to this file, and (b) compute & use absolute path, and (c) replace python3 with python
subprocess.run(['python', os.path.join(k_path, 'kamfadm-2012ecmlpkdd', 'predict_lr.py'),
'-i', test_name,
'-m', self.model_name,
'-o', output_name,
'--quiet'])
subprocess.call(['python', os.path.join(k_path, 'kamfadm-2012ecmlpkdd', 'predict_lr.py'),
'-i', test_name,
'-m', self.model_name,
'-o', output_name,
'--quiet'])

#os.unlink(model_name)
os.unlink(test_name)
Expand Down

0 comments on commit 57135d0

Please sign in to comment.