Skip to content

Commit 7f2a8cc

Browse files
authored
Merge pull request #74 from tushushu/wip-remove-bool-replace
remove replace method of `BooleanList`
2 parents 77780ce + 0b9fc7e commit 7f2a8cc

File tree

9 files changed

+16
-22
lines changed

9 files changed

+16
-22
lines changed

tests/test_base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ def test_methods_no_arg(
102102
('get', 'float', [1.0, 2.0, 3.0], 2.0, {'index': 1}),
103103
('get', 'int', [1, 2, 3], 1, {'index': 0}),
104104
105-
('replace', 'bool', [True, False, True], [
106-
False, False, False], {'old': True, 'new': False}),
107-
('replace', 'float', [1.0, 0.0, 1.0], [
108-
0.0, 0.0, 0.0], {'old': 1.0, 'new': 0.0}),
109-
('replace', 'int', [1, 0, 1], [0, 0, 0], {'old': 1, 'new': 0}),
110-
111105
('var', 'bool', [True, False], 0.25, {}),
112106
('var', 'bool', [True, True, True, False], 0.25, {"ddof": 1}),
113107
('var', 'float', [1.0, 2.0, 3.0, 4.0], 1.25, {}),

tests/test_numerical.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def test_statistics_methods(
4747
@pytest.mark.parametrize(
4848
"test_method, dtype, nums, expected_value, kwargs",
4949
[
50+
('replace', 'float', [1.0, 0.0, 1.0], [
51+
0.0, 0.0, 0.0], {'old': 1.0, 'new': 0.0}),
52+
('replace', 'int', [1, 0, 1], [0, 0, 0], {'old': 1, 'new': 0}),
53+
5054
(
5155
'sort',
5256
'float',

ulist/python/ulist/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def pow_scala(self, num: int) -> "UltraFastList":
293293

294294
def replace(self, old: ELEM, new: ELEM) -> "UltraFastList":
295295
"""Replace the old elements of self with the new one."""
296+
assert not isinstance(self._values, BooleanList)
296297
return UltraFastList(self._values.replace(old, new))
297298

298299
def set(self, index: int, num: ELEM) -> None:

ulist/python/ulist/ulist.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class BooleanList:
2222
def pop(self): ...
2323
@staticmethod
2424
def repeat(num: bool, size: int) -> BooleanList: ...
25-
def replace(self, old: ELEM, new: ELEM) -> BooleanList: ...
2625
def set(self, index: int, num: ELEM): ...
2726
def size(self) -> int: ...
2827
def sum(self) -> int: ...

ulist/src/base.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ where
5454
List::_new(vec)
5555
}
5656

57-
fn replace(&self, old: T, new: T) -> Self {
58-
let vec = self
59-
.values()
60-
.iter()
61-
.map(|&x| if x == old { new } else { x })
62-
.collect();
63-
List::_new(vec)
64-
}
65-
6657
fn size(&self) -> usize {
6758
self.values().len()
6859
}

ulist/src/boolean.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ impl BooleanList {
7979
List::repeat(num, size)
8080
}
8181

82-
pub fn replace(&self, old: bool, new: bool) -> Self {
83-
List::replace(self, old, new)
84-
}
85-
8682
pub unsafe fn set(&self, index: usize, num: bool) {
8783
List::set(self, index, num)
8884
}

ulist/src/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl FloatList {
133133
}
134134

135135
pub fn replace(&self, old: f32, new: f32) -> Self {
136-
List::replace(self, old, new)
136+
NumericalList::replace(self, old, new)
137137
}
138138

139139
pub unsafe fn set(&self, index: usize, num: f32) {

ulist/src/integer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl IntegerList {
137137
}
138138

139139
pub fn replace(&self, old: i32, new: i32) -> Self {
140-
List::replace(self, old, new)
140+
NumericalList::replace(self, old, new)
141141
}
142142

143143
pub fn size(&self) -> usize {

ulist/src/numerical.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ where
9595

9696
fn pow_scala(&self, num: V) -> Self;
9797

98+
fn replace(&self, old: T, new: T) -> Self {
99+
let vec = self
100+
.values()
101+
.iter()
102+
.map(|&x| if x == old { new } else { x })
103+
.collect();
104+
List::_new(vec)
105+
}
106+
98107
fn sort(&self, ascending: bool) -> Self {
99108
let mut vec = self.to_list();
100109
let mut _vec = &mut vec;

0 commit comments

Comments
 (0)