Skip to content

Commit 1178849

Browse files
committed
renamed
1 parent f2ceefc commit 1178849

4 files changed

Lines changed: 42 additions & 45 deletions

File tree

src/valor_lite/cache/ephemeral.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pyarrow as pa
55

66

7-
class EphemeralCache:
7+
class MemoryCache:
88
def __init__(self, table: pa.Table):
99
self._table = table
1010

@@ -13,7 +13,7 @@ def count_rows(self) -> int:
1313
return self._table.num_rows
1414

1515

16-
class EphemeralCacheWriter(EphemeralCache):
16+
class MemoryCacheWriter(MemoryCache):
1717
def __init__(
1818
self,
1919
table: pa.Table,
@@ -147,22 +147,22 @@ def __exit__(self, exc_type, exc_val, exc_tb):
147147
self.flush()
148148

149149

150-
class EphemeralCacheReader:
150+
class MemoryCacheReader:
151151
def __init__(
152152
self,
153-
cache: EphemeralCacheWriter,
153+
cache: MemoryCacheWriter,
154154
):
155155
self._cache = cache
156156
self._schema = self._cache._schema
157157

158158
@classmethod
159-
def load(cls, cache: EphemeralCacheWriter):
159+
def load(cls, cache: MemoryCacheWriter):
160160
"""
161161
Load cache from table.
162162
163163
Parameters
164164
----------
165-
cache : EphemeralCacheWriter
165+
cache : MemoryCacheWriter
166166
A cache writer containing the ephemeral cache.
167167
"""
168168
return cls(cache=cache)

src/valor_lite/cache/persistent.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pyarrow.parquet as pq
1212

1313

14-
class PersistentCache:
14+
class FileCache:
1515
def __init__(self, path: str | Path):
1616
self._path = Path(path)
1717

@@ -80,7 +80,7 @@ def get_dataset_files(self) -> list[Path]:
8080
]
8181

8282

83-
class PersistentCacheWriter(PersistentCache):
83+
class FileCacheWriter(FileCache):
8484
def __init__(
8585
self,
8686
path: str | Path,
@@ -298,7 +298,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
298298
self.flush()
299299

300300

301-
class PersistentCacheReader(PersistentCache):
301+
class FileCacheReader(FileCache):
302302
def __init__(
303303
self,
304304
path: str | Path,
@@ -308,7 +308,7 @@ def __init__(
308308
self._path = Path(path)
309309

310310
@classmethod
311-
def load(cls, path: str | Path | PersistentCache):
311+
def load(cls, path: str | Path | FileCache):
312312
"""
313313
Load cache from disk.
314314
@@ -317,7 +317,7 @@ def load(cls, path: str | Path | PersistentCache):
317317
path : str | Path
318318
Where the cache is stored.
319319
"""
320-
if isinstance(path, PersistentCache):
320+
if isinstance(path, FileCache):
321321
path = path.path
322322
path = Path(path)
323323
if not path.exists():

tests/common/test_ephemeral_cache.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import numpy as np
22
import pyarrow as pa
33

4-
from valor_lite.cache.ephemeral import (
5-
EphemeralCacheReader,
6-
EphemeralCacheWriter,
7-
)
4+
from valor_lite.cache.ephemeral import MemoryCacheReader, MemoryCacheWriter
85

96

107
def test_cache_reader():
@@ -16,7 +13,7 @@ def test_cache_reader():
1613
("some_str", pa.string()),
1714
]
1815
)
19-
with EphemeralCacheWriter.create(
16+
with MemoryCacheWriter.create(
2017
schema=schema,
2118
batch_size=batch_size,
2219
) as writer:
@@ -33,7 +30,7 @@ def test_cache_reader():
3330
writer.write_table(tbl)
3431
assert writer.count_rows() == 101
3532

36-
reader = EphemeralCacheReader.load(writer)
33+
reader = MemoryCacheReader.load(writer)
3734
assert reader.count_rows() == 101
3835
for tbl in reader.iterate_tables():
3936
assert tbl["some_int"].to_pylist() == [i for i in range(101)]
@@ -45,7 +42,7 @@ def test_cache_reader():
4542

4643
def test_cache_write_batch():
4744
batch_size = 10
48-
with EphemeralCacheWriter.create(
45+
with MemoryCacheWriter.create(
4946
schema=pa.schema(
5047
[
5148
("some_int", pa.int64()),
@@ -64,7 +61,7 @@ def test_cache_write_batch():
6461
}
6562
)
6663

67-
reader = EphemeralCacheReader(writer)
64+
reader = MemoryCacheReader(writer)
6865
assert reader.count_rows() == 1000
6966
for tbl in reader.iterate_tables():
7067
assert tbl["some_int"].to_pylist() == [i for i in range(1000)]
@@ -74,7 +71,7 @@ def test_cache_write_batch():
7471

7572
def test_cache_write_rows():
7673
batch_size = 10
77-
with EphemeralCacheWriter.create(
74+
with MemoryCacheWriter.create(
7875
schema=pa.schema(
7976
[
8077
("some_int", pa.int64()),
@@ -99,7 +96,7 @@ def test_cache_write_rows():
9996
writer.write_rows([])
10097
assert len(writer._buffer) == buffer_size
10198

102-
reader = EphemeralCacheReader.load(writer)
99+
reader = MemoryCacheReader.load(writer)
103100
assert reader.count_rows() == 1000
104101
for tbl in reader.iterate_tables():
105102
assert tbl["some_int"].to_pylist() == [i for i in range(1000)]
@@ -109,7 +106,7 @@ def test_cache_write_rows():
109106

110107
def test_cache_write_table():
111108
batch_size = 10
112-
with EphemeralCacheWriter.create(
109+
with MemoryCacheWriter.create(
113110
schema=pa.schema(
114111
[
115112
("some_int", pa.int64()),
@@ -137,7 +134,7 @@ def test_cache_write_table():
137134
writer.write_table(tbl)
138135
assert writer.count_rows() == 202
139136

140-
reader = EphemeralCacheReader.load(writer)
137+
reader = MemoryCacheReader.load(writer)
141138

142139
for tbl in reader.iterate_tables():
143140
assert tbl["some_int"].to_pylist() == [i for i in range(101)] + [
@@ -153,7 +150,7 @@ def test_cache_write_table():
153150

154151
def test_cache_delete():
155152
batch_size = 10
156-
with EphemeralCacheWriter.create(
153+
with MemoryCacheWriter.create(
157154
schema=pa.schema(
158155
[
159156
("some_int", pa.int64()),
@@ -183,7 +180,7 @@ def test_cache_delete():
183180

184181
writer.flush()
185182

186-
reader = EphemeralCacheReader.load(writer)
183+
reader = MemoryCacheReader.load(writer)
187184
for tbl in reader.iterate_tables():
188185
assert tbl["some_int"].to_pylist() == [i for i in range(101)] + [
189186
i for i in range(101)

tests/common/test_persistent_cache.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import pytest
77

88
from valor_lite.cache.persistent import (
9-
PersistentCache,
10-
PersistentCacheReader,
11-
PersistentCacheWriter,
9+
FileCache,
10+
FileCacheReader,
11+
FileCacheWriter,
1212
)
1313

1414

1515
def test_cache_files_empty(tmp_path: Path):
16-
cache = PersistentCache(tmp_path)
16+
cache = FileCache(tmp_path)
1717
assert cache._path == tmp_path
1818
assert cache.get_files() == []
1919
assert cache.get_dataset_files() == []
@@ -22,7 +22,7 @@ def test_cache_files_empty(tmp_path: Path):
2222

2323
def test_cache_files_does_not_exist(tmp_path: Path):
2424
path = tmp_path / "does_not_exist"
25-
cache = PersistentCache(path)
25+
cache = FileCache(path)
2626
assert cache._path == path
2727
assert cache.get_files() == []
2828
assert cache.get_dataset_files() == []
@@ -39,7 +39,7 @@ def test_cache_reader(tmp_path: Path):
3939
("some_str", pa.string()),
4040
]
4141
)
42-
with PersistentCacheWriter.create(
42+
with FileCacheWriter.create(
4343
path=tmp_path / "cache",
4444
schema=schema,
4545
batch_size=batch_size,
@@ -57,7 +57,7 @@ def test_cache_reader(tmp_path: Path):
5757
)
5858

5959
writer.write_table(tbl)
60-
reader = PersistentCacheReader.load(tmp_path / "cache")
60+
reader = FileCacheReader.load(tmp_path / "cache")
6161
assert set(reader.get_files()) == set(
6262
[
6363
tmp_path / "cache" / "000000.parquet",
@@ -99,7 +99,7 @@ def test_cache_reader(tmp_path: Path):
9999
def test_cache_reader_does_not_exist(tmp_path: Path):
100100
path = tmp_path / "does_not_exist"
101101
with pytest.raises(FileNotFoundError):
102-
PersistentCacheReader.load(path)
102+
FileCacheReader.load(path)
103103

104104

105105
def test_cache_reader_not_a_directory(tmp_path: Path):
@@ -108,7 +108,7 @@ def test_cache_reader_not_a_directory(tmp_path: Path):
108108
f.write("hello world")
109109

110110
with pytest.raises(NotADirectoryError):
111-
PersistentCacheReader.load(filepath)
111+
FileCacheReader.load(filepath)
112112

113113

114114
def test_cache_reader_config_error(tmp_path: Path):
@@ -122,13 +122,13 @@ def test_cache_reader_config_error(tmp_path: Path):
122122
]
123123
)
124124
path = tmp_path / "cache"
125-
with PersistentCacheWriter.create(
125+
with FileCacheWriter.create(
126126
path=path,
127127
schema=schema,
128128
batch_size=batch_size,
129129
rows_per_file=rows_per_file,
130130
) as writer:
131-
reader = PersistentCacheReader.load(writer.path)
131+
reader = FileCacheReader.load(writer.path)
132132
assert reader.path == path
133133
assert len(reader.get_files()) == 1
134134
assert reader.get_files() == [path / ".cfg"]
@@ -141,13 +141,13 @@ def test_cache_reader_config_error(tmp_path: Path):
141141
json.dump({}, f, indent=2)
142142

143143
with pytest.raises(KeyError):
144-
PersistentCacheReader.load(writer.path)
144+
FileCacheReader.load(writer.path)
145145

146146

147147
def test_cache_write_batch(tmp_path: Path):
148148
batch_size = 10
149149
rows_per_file = 100
150-
with PersistentCacheWriter.create(
150+
with FileCacheWriter.create(
151151
path=tmp_path / "cache",
152152
schema=pa.schema(
153153
[
@@ -170,7 +170,7 @@ def test_cache_write_batch(tmp_path: Path):
170170
writer.flush()
171171
assert len(writer.get_files()) == 11
172172

173-
reader = PersistentCacheReader.load(writer.path)
173+
reader = FileCacheReader.load(writer.path)
174174
assert reader.count_rows() == 1000
175175
for idx, tbl in enumerate(reader.iterate_tables()):
176176
assert tbl["some_int"].to_pylist() == [
@@ -190,7 +190,7 @@ def test_cache_write_batch(tmp_path: Path):
190190
def test_cache_write_rows(tmp_path: Path):
191191
batch_size = 10
192192
rows_per_file = 100
193-
with PersistentCacheWriter.create(
193+
with FileCacheWriter.create(
194194
path=tmp_path / "cache",
195195
schema=pa.schema(
196196
[
@@ -219,7 +219,7 @@ def test_cache_write_rows(tmp_path: Path):
219219
writer.flush()
220220
assert len(writer.get_files()) == 11
221221

222-
reader = PersistentCacheReader.load(writer.path)
222+
reader = FileCacheReader.load(writer.path)
223223
assert reader.count_rows() == 1000
224224
for idx, tbl in enumerate(reader.iterate_tables()):
225225
assert tbl["some_int"].to_pylist() == [
@@ -239,7 +239,7 @@ def test_cache_write_rows(tmp_path: Path):
239239
def test_cache_write_table(tmp_path: Path):
240240
batch_size = 10
241241
rows_per_file = 100
242-
with PersistentCacheWriter.create(
242+
with FileCacheWriter.create(
243243
path=tmp_path / "cache",
244244
schema=pa.schema(
245245
[
@@ -267,7 +267,7 @@ def test_cache_write_table(tmp_path: Path):
267267
assert len(writer.get_files()) == 3
268268
writer.flush()
269269

270-
reader = PersistentCacheReader.load(writer.path)
270+
reader = FileCacheReader.load(writer.path)
271271
assert reader.count_rows() == 202
272272
for tbl in reader.iterate_tables():
273273
assert tbl["some_int"].to_pylist() == [i for i in range(101)]
@@ -280,7 +280,7 @@ def test_cache_write_table(tmp_path: Path):
280280
def test_cache_delete(tmp_path: Path):
281281
batch_size = 10
282282
rows_per_file = 100
283-
with PersistentCacheWriter.create(
283+
with FileCacheWriter.create(
284284
path=tmp_path / "cache",
285285
schema=pa.schema(
286286
[
@@ -308,7 +308,7 @@ def test_cache_delete(tmp_path: Path):
308308
assert len(writer.get_files()) == 3
309309
writer.flush()
310310

311-
reader = PersistentCacheReader.load(path=writer.path)
311+
reader = FileCacheReader.load(path=writer.path)
312312
assert reader.count_rows() == 202
313313
for tbl in reader.iterate_tables():
314314
assert tbl["some_int"].to_pylist() == [i for i in range(101)]

0 commit comments

Comments
 (0)