Skip to content

Dead code in TriangleDunders._prep_index() #1044

Description

@genedan

Are you on the latest chainladder version?

  • Yes, this bug occurs on the latest version.

Describe the bug in words

Working on this, it's a quick fix. I was trying to write a test for line 112 in TriangleDunders._prep_index(), which is uncovered. But it's also unreachable.

def _prep_index(self, x, y):
if x.kdims.shape[0] == 1 and y.kdims.shape[0] > 1:
x.kdims = y.kdims
x.key_labels = y.key_labels
return x, y
if x.kdims.shape[0] > 1 and y.kdims.shape[0] == 1:
y.kdims = x.kdims
y.key_labels = x.key_labels
return x, y
if x.kdims.shape[0] == y.kdims.shape[0] == 1 and x.key_labels != y.key_labels:
kdims = x.kdims if len(x.key_labels) > len(y.key_labels) else y.kdims
key_labels = x.key_labels if len(x.key_labels) > len(y.key_labels) else y.key_labels
x.kdims = y.kdims = kdims
x.key_labels = y.key_labels = key_labels
return x, y
# Use sets for faster operations
x_labels = set(x.key_labels)
y_labels = set(y.key_labels)
common = x_labels.intersection(y_labels)
if common == x_labels or common == y_labels:
if x_labels != y_labels or x.kdims.shape[0] != y.kdims.shape[0]:
x = x.groupby(list(common))
y = y.groupby(list(common))
elif x.kdims.shape[0] > 1 and not np.array_equal(x.kdims, y.kdims) and not x.index.equals(y.index):
x = x.sort_index()
try:
y = y.loc[x.index]
except:
x = x.groupby(list(common))
y = y.groupby(list(common))
return x, y
if common != x_labels and common != y_labels:
raise ValueError('Index broadcasting is ambiguous between ' + str(x_labels) + ' and ' + str(y_labels))
return x, y

How can the bug be reproduced?

Condition common == x_labels or common == y_labels is the negation of the next if statement condition common != x_labels and common != y_labels, so line 112 can't be reached.

What is the expected behavior?

Remove line 112, edit the 2nd condition to be a simple else: statement.

Would you be willing to contribute this ticket?

  • Yes, absolutely!
  • Yes, but I would like some help.
  • No.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

Priority

Low

Effort

Low

Scope

Codebase

Projects

Status
Backlog

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions