Skip to content

Commit 7a74d6a

Browse files
committed
Use textwrap to shorten debug description
1 parent c9346b4 commit 7a74d6a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

datastream/dataset.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Tuple, Callable, Any, Union, List, TypeVar, Generic, Dict, Optional
55
)
66
from pathlib import Path
7+
from functools import lru_cache
8+
import textwrap
79
import inspect
810
import numpy as np
911
import pandas as pd
@@ -132,9 +134,7 @@ def composed_fn(dataframe, index):
132134
try:
133135
return function(item)
134136
except Exception as e:
135-
item_text = str(item)
136-
if len(item_text) > 79:
137-
item_text = item_text[:79] + ' ...'
137+
item_text = textwrap.shorten(str(item), width=79)
138138

139139
raise Exception('\n'.join([
140140
repr(e),
@@ -487,10 +487,11 @@ def zip(datasets: List[Dataset]) -> Dataset[Tuple]:
487487
))
488488
)
489489

490-
def cache(self, key_column):
491-
'''Cache dataset in-memory based on key column.'''
492-
from functools import lru_cache
493-
490+
def cache(
491+
self,
492+
key_column: str,
493+
):
494+
'''Cache intermediate step in-memory based on key column.'''
494495
key_mapping = dict(zip(
495496
self.dataframe[key_column],
496497
range(len(self)),

datastream/datastream.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
)
1313
import numpy as np
1414
import torch
15+
from pathlib import Path
1516

1617
from datastream import Dataset
1718
from datastream.samplers import (
@@ -253,7 +254,10 @@ def multi_sample(self: Datastream[T], n: int) -> Datastream[T]:
253254
MultiSampler.from_number(n, self.dataset),
254255
)
255256

256-
def cache(self, key_column):
257+
def cache(
258+
self,
259+
key_column: str,
260+
):
257261
'''Cache dataset in-memory. See :func:`Dataset.cache` for details.'''
258262
return Datastream(
259263
self.dataset.cache(key_column),

0 commit comments

Comments
 (0)