Skip to content

Commit b491bb5

Browse files
committed
refactor: make args default to an empty list in Workspace constructor
1 parent 7cb01a6 commit b491bb5

16 files changed

+34
-34
lines changed

docs/source/how_to_guides/cache_format.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
" \"0 | price:.53 sqft:.32 age:.87 1924\",\n",
3535
"]\n",
3636
"\n",
37-
"workspace = vw.Workspace([])\n",
37+
"workspace = vw.Workspace()\n",
3838
"text_parser = vw.TextFormatParser(workspace)\n",
3939
"\n",
4040
"with open(\"data.cache\", \"wb\") as cache_file:\n",
@@ -67,7 +67,7 @@
6767
}
6868
],
6969
"source": [
70-
"workspace = vw.Workspace([])\n",
70+
"workspace = vw.Workspace()\n",
7171
"text_parser = vw.TextFormatParser(workspace)\n",
7272
"\n",
7373
"with open(\"data.cache\", \"rb\") as cache_file:\n",

docs/source/how_to_guides/dataset_readers.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"source": [
3939
"import vowpal_wabbit_next as vw\n",
4040
"\n",
41-
"workspace = vw.Workspace([])\n",
41+
"workspace = vw.Workspace()\n",
4242
"\n",
4343
"with open(\"example.txt\", \"r\") as text_file:\n",
4444
" with vw.TextFormatReader(workspace, text_file) as reader:\n",

docs/source/how_to_guides/save_load_models.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"source": [
3030
"import vowpal_wabbit_next as vw\n",
3131
"\n",
32-
"workspace = vw.Workspace([])\n",
32+
"workspace = vw.Workspace()\n",
3333
"\n",
3434
"text_parser = vw.TextFormatParser(workspace)\n",
3535
"\n",
@@ -39,7 +39,7 @@
3939
"\n",
4040
"serialized_workspace = workspace.serialize()\n",
4141
"\n",
42-
"loaded_workspace = vw.Workspace([], model_data=serialized_workspace)\n",
42+
"loaded_workspace = vw.Workspace(model_data=serialized_workspace)\n",
4343
"text_parser2 = vw.TextFormatParser(loaded_workspace)\n",
4444
"\n",
4545
"print(workspace.predict_one(text_parser.parse_line(\"| a:0.7 c:0.6\")))\n",

src/vowpal_wabbit_next/cache_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, workspace: Workspace, file: typing.BinaryIO):
1212
1313
Examples:
1414
>>> from vowpal_wabbit_next import Workspace, TextFormatParser, CacheFormatWriter
15-
>>> workspace = Workspace([])
15+
>>> workspace = Workspace()
1616
>>> with open("data.cache", "rb") as f:
1717
... with CacheFormatReader(workspace, f) as reader:
1818
... for example in reader:
@@ -77,7 +77,7 @@ def __init__(self, workspace: Workspace, file: typing.BinaryIO):
7777
7878
Examples:
7979
>>> from vowpal_wabbit_next import Workspace, TextFormatParser, CacheFormatWriter
80-
>>> workspace = Workspace([])
80+
>>> workspace = Workspace()
8181
>>> parser = TextFormatParser(workspace)
8282
>>> with open("data.cache", "wb") as f:
8383
... with CacheFormatWriter(workspace, f) as writer:

src/vowpal_wabbit_next/dsjson_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, workspace: Workspace, file: typing.TextIO):
5858
5959
Examples:
6060
>>> from vowpal_wabbit_next import Workspace, DSJsonFormatReader
61-
>>> workspace = Workspace([])
61+
>>> workspace = Workspace()
6262
>>> with open("data.txt", "r") as f:
6363
... with DSJsonFormatReader(workspace, f) as reader:
6464
... for example in reader:

src/vowpal_wabbit_next/text_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_line(self, text: str) -> Example:
1818
1919
Examples:
2020
>>> from vowpal_wabbit_next import Workspace, TextFormatParser
21-
>>> workspace = Workspace([])
21+
>>> workspace = Workspace()
2222
>>> parser = TextFormatParser(workspace)
2323
>>> example = parser.parse_line("1.0 | price:.18 sqft:.15 age:.35 1976")
2424
@@ -44,7 +44,7 @@ def __init__(self, workspace: Workspace, file: typing.TextIO):
4444
4545
Examples:
4646
>>> from vowpal_wabbit_next import Workspace, TextFormatReader
47-
>>> workspace = Workspace([])
47+
>>> workspace = Workspace()
4848
>>> with open("data.txt", "r") as f:
4949
... with TextFormatReader(workspace, f) as reader:
5050
... for example in reader:

src/vowpal_wabbit_next/workspace.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
class Workspace:
3939
def __init__(
4040
self,
41-
args: List[str],
41+
args: List[str] = [],
4242
*,
4343
model_data: Optional[bytes] = None,
4444
record_feature_names: bool = False,
@@ -59,7 +59,7 @@ def __init__(
5959
>>> from vowpal_wabbit_next import Workspace
6060
>>> with open("model.bin", "rb") as f:
6161
... model_data = f.read()
62-
>>> workspace = Workspace([], model_data=model_data)
62+
>>> workspace = Workspace(model_data=model_data)
6363
6464
Create a workspace for training a contextual bandit with action dependent features model:
6565
@@ -72,7 +72,7 @@ def __init__(
7272
>>> import logging
7373
>>> logging.basicConfig(level=logging.INFO)
7474
>>> logging.getLogger("vowpal_wabbit_next.log").setLevel("INFO")
75-
>>> workspace = Workspace([])
75+
>>> workspace = Workspace()
7676
7777
Args:
7878
args (List[str]): VowpalWabbit command line options for configuring the model. An overall list can be found `here <https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/command_line_args.html>`_. Options which affect the driver are not supported. For example:
@@ -110,7 +110,7 @@ def predict_one(self, example: typing.Union[Example, List[Example]]) -> Predicti
110110
111111
Examples:
112112
>>> from vowpal_wabbit_next import Workspace, TextFormatParser
113-
>>> workspace = Workspace([])
113+
>>> workspace = Workspace()
114114
>>> parser = TextFormatParser(workspace)
115115
>>> workspace.learn_one(parser.parse_line("1.0 | price:.18 sqft:.15 age:.35 1976"))
116116
>>> workspace.predict_one(parser.parse_line("| price:.53 sqft:.32 age:.87 1924"))
@@ -134,7 +134,7 @@ def learn_one(self, example: typing.Union[Example, List[Example]]) -> None:
134134
135135
Examples:
136136
>>> from vowpal_wabbit_next import Workspace, TextFormatParser
137-
>>> workspace = Workspace([])
137+
>>> workspace = Workspace()
138138
>>> parser = TextFormatParser(workspace)
139139
>>> workspace.learn_one(parser.parse_line("1.0 | price:.18 sqft:.15 age:.35 1976"))
140140
>>> workspace.predict_one(parser.parse_line("| price:.53 sqft:.32 age:.87 1924"))
@@ -157,7 +157,7 @@ def predict_then_learn_one(
157157
158158
Examples:
159159
>>> from vowpal_wabbit_next import Workspace, TextFormatParser
160-
>>> workspace = Workspace([])
160+
>>> workspace = Workspace()
161161
>>> parser = TextFormatParser(workspace)
162162
>>> workspace.predict_then_learn_one(parser.parse_line("1.0 | price:.18 sqft:.15 age:.35 1976"))
163163
0.0
@@ -244,7 +244,7 @@ def weights(self) -> npt.NDArray[np.float32]:
244244
245245
Examples:
246246
>>> from vowpal_wabbit_next import Workspace
247-
>>> model = Workspace([])
247+
>>> model = Workspace()
248248
>>> print(model.weights().shape)
249249
(262144, 1, 4)
250250
@@ -309,7 +309,7 @@ def get_index_for_scalar_feature(
309309
310310
Examples:
311311
>>> from vowpal_wabbit_next import Workspace
312-
>>> model = Workspace([])
312+
>>> model = Workspace()
313313
>>> # Feature which looks like "|test thing" in text format
314314
>>> model.get_index_for_scalar_feature("thing", namespace_name="test")
315315
148099

tests/test_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_write_and_read_cache() -> None:
1414

1515
cache_buffer = io.BytesIO()
1616
read_buffer = io.BytesIO()
17-
workspace = vw.Workspace([])
17+
workspace = vw.Workspace()
1818
write_counter = 0
1919
with vw.TextFormatReader(workspace, text_input) as reader:
2020
with vw.CacheFormatWriter(workspace, cache_buffer) as writer:

tests/test_debug.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def test_json_weights() -> None:
2020

2121

2222
def test_json_weights_feat_name_without_constructor_enabled() -> None:
23-
model = vw.Workspace([])
23+
model = vw.Workspace()
2424
with pytest.raises(RuntimeError):
2525
model.json_weights(include_feature_names=True)
2626

2727

2828
def test_readable_model():
29-
model = vw.Workspace([], record_feature_names=True)
29+
model = vw.Workspace(, record_feature_names=True)
3030
parser = vw.TextFormatParser(model)
3131
model.learn_one(parser.parse_line("1 | MY_SUPER_UNIQUE_FEATURE_NAME"))
3232
assert "MY_SUPER_UNIQUE_FEATURE_NAME" in model.readable_model(
@@ -35,6 +35,6 @@ def test_readable_model():
3535

3636

3737
def test_readable_model_feat_name_without_constructor_enabled():
38-
model = vw.Workspace([])
38+
model = vw.Workspace()
3939
with pytest.raises(RuntimeError):
4040
model.readable_model(include_feature_names=True)

tests/test_delta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_equivalent_models() -> None:
88

99
model.learn_one(parser.parse_line("1 | a b c"))
1010

11-
model_after_1_learn = vw.Workspace([], model_data=model.serialize())
11+
model_after_1_learn = vw.Workspace(model_data=model.serialize())
1212

1313
model.learn_one(parser.parse_line("1 | d e f"))
1414

0 commit comments

Comments
 (0)