Skip to content

Commit

Permalink
#358: stringify properties and controls, addresses #357
Browse files Browse the repository at this point in the history
  • Loading branch information
cmacdonald authored Jan 4, 2023
2 parents d2dfb54 + 4b68c6d commit 65fba48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pyterrier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ def set_property(k, v):
methods or arguments. So this method should be seen as a safety-valve - a way to override the
Terrier configuration not explicitly supported by PyTerrier.
"""
properties[k] = v
properties[str(k)] = str(v)
ApplicationSetup.bootstrapInitialisation(properties)

def set_properties(kwargs):
"""
Allows to set many properties in Terrier's global properties configuration
"""
for control, value in kwargs.items():
properties.put(control, value)
for key, value in kwargs.items():
properties[str(key)] = str(value)
ApplicationSetup.bootstrapInitialisation(properties)

def run(cmd, args=[]):
Expand Down
6 changes: 3 additions & 3 deletions pyterrier/batchretrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def __init__(self, index_location, controls=None, properties=None, metadata=["do
if props is None:
importProps()
for key, value in self.properties.items():
self.appSetup.setProperty(key, str(value))
self.appSetup.setProperty(str(key), str(value))

self.controls = _mergeDicts(BatchRetrieve.default_controls, controls)
if wmodel is not None:
Expand Down Expand Up @@ -459,10 +459,10 @@ def __str__(self):

def setControls(self, controls):
for key, value in controls.items():
self.controls[key] = value
self.controls[str(key)] = str(value)

def setControl(self, control, value):
self.controls[control] = value
self.controls[str(control)] = str(value)



Expand Down
6 changes: 3 additions & 3 deletions pyterrier/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def setProperty(self, k, v):
Usage::
indexer.setProperty("termpipelines", "")
"""
self.properties.put(k, v)
self.properties.put(str(k), str(v))

def setProperties(self, **kwargs):
"""
Expand All @@ -450,8 +450,8 @@ def setProperties(self, **kwargs):
Usage:
>>> setProperties(**{property1:value1, property2:value2})
"""
for control, value in kwargs.items():
self.properties.put(control, value)
for key, value in kwargs.items():
self.properties.put(str(key), str(value))

def checkIndexExists(self):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import unittest
import pyterrier as pt, pandas as pd
from .base import BaseTestCase

class TestInit(BaseTestCase):

def test_set_property(self):
pt.set_property("arbitrary.property", 40)
self.assertEqual("40", pt.ApplicationSetup.appProperties.getProperty("arbitrary.property", "none"))

0 comments on commit 65fba48

Please sign in to comment.