Skip to content

Commit

Permalink
fix(core): Correct repr formatting of ranges for numpy version 2.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed Jul 15, 2024
1 parent 52ca981 commit 812abb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion formulas/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,15 @@ def _merge(self):

def __repr__(self):
ranges = ', '.join(r['name'] for r in self.ranges)
value = '={}'.format(self.value) if ranges and self.values else ''
if ranges and self.values:
value = '={}'.format(self.value)
if 'np.' in value: # Correct formatting for numpy v2.x.
value = '={}'.format(np.array2string(
self.value, formatter={'all': '{}'.format}
))
else:
value = ''

return '<%s>(%s)%s' % (self.__class__.__name__, ranges, value)

@property
Expand Down
4 changes: 2 additions & 2 deletions test/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ class TestCell(unittest.TestCase):
('A1', '=CORREL(A2,{8,2})', {'A2': [[sh.EMPTY]]},
'<Ranges>(A1)=[[#VALUE!]]'),
('A1', '=CORREL({"2",4,1},{7,3,6})', {}, '<Ranges>(A1)=[[-1.0]]'),
('A1', '=CORREL({2,4,1},{7,3,6})', {},
'<Ranges>(A1)=[[-0.8386278693775346]]'),
('A1', '=IPMT(0.1/12, 60, 3*12, 8000)', {},
'<Ranges>(A1)=[[#NUM!]]'),
('A1', '=PMT(0.08/12,0,10000)', {}, '<Ranges>(A1)=[[#NUM!]]'),
Expand Down Expand Up @@ -719,6 +717,8 @@ def test_output(self, case):
'<Ranges>\(A1\)=\[\[-1030.1643271779\d*\]\]'),
('A1', '=PMT(0.08/12,10,10000)', {},
'<Ranges>\(A1\)=\[\[-1037.0320893591\d*\]\]'),
('A1', '=CORREL({2,4,1},{7,3,6})', {},
'<Ranges>\(A1\)=\[\[-0.838627869377534\d*\]\]'),
])
def test_output_regex(self, case):
reference, formula, inputs, regex = case
Expand Down

0 comments on commit 812abb0

Please sign in to comment.