Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Common/PandasMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def __new__(cls, key):

def __eq__(self, other):
# We need this since Lean created data frames might contain Symbol objects in the indexes
return super().__eq__(other) and type(other) is not Symbol
if type(other) is Symbol:
return False
# For non-strings str.__eq__ returns NotImplemented, which Python resolves to False
return super().__eq__(other)

def __hash__(self):
return super().__hash__()
Expand Down
12 changes: 12 additions & 0 deletions Tests/Python/PandasIndexingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,17 @@ public void ExpectedException()
Assert.IsTrue(exception.Contains("No key found for either mapped or original key.", StringComparison.InvariantCulture), exception);
}
}

[Test]
public void ColumnEqualsOnlyMatchingString()
{
using (Py.GIL())
{
PyObject result = _pandasDataFrameTests.test_column_equals_only_matching_string();
var test = result.As<bool>();

Assert.IsTrue(test);
}
}
}
}
6 changes: 6 additions & 0 deletions Tests/Python/PandasTests/PandasIndexingTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from AlgorithmImports import *
from QuantConnect.Tests import *
from QuantConnect.Tests.Python import *
from PandasMapper import PandasColumn

# TODO: Rename to PandasResearchTests and keep this class for QB related tests; rename py module to PandasTests
class PandasIndexingTests():
Expand Down Expand Up @@ -68,3 +69,8 @@ def test_contains_user_defined_columns_with_spaces(self, column_name):
return True
except:
return False

def test_column_equals_only_matching_string(self):
# A column label should only equal a matching string, never None/ints/floats
column = PandasColumn("shares")
return (not (column == None)) and (not (column == 0)) and (not (column == 123)) and (column == "shares")
Loading