MCPcopy
hub / github.com/microsoft/qlib / test_corner_cases

Method test_corner_cases

tests/misc/test_index_data.py:72–113  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

70 print(sd.loc[:"c"])
71
72 def test_corner_cases(self):
73 sd = idd.MultiData([[1, 2], [3, np.nan]], index=["foo", "bar"], columns=["f", "g"])
74 print(sd)
75
76 self.assertTrue(np.isnan(sd.loc["bar", "g"]))
77
78 # support slicing
79 print(sd.loc[~sd.loc[:, "g"].isna().data.astype(bool)])
80
81 print(self.assertTrue(idd.SingleData().index == idd.SingleData().index))
82
83 # empty dict
84 print(idd.SingleData({}))
85 print(idd.SingleData(pd.Series()))
86
87 sd = idd.SingleData()
88 with self.assertRaises(KeyError):
89 sd.loc["foo"]
90
91 # replace
92 sd = idd.SingleData([1, 2, 3, 4], index=["foo", "bar", "f", "g"])
93 sd = sd.replace(dict(zip(range(1, 5), range(2, 6))))
94 print(sd)
95 self.assertTrue(sd.iloc[0] == 2)
96
97 # test different precisions of time data
98 timeindex = [
99 np.datetime64("2024-06-22T00:00:00.000000000"),
100 np.datetime64("2024-06-21T00:00:00.000000000"),
101 np.datetime64("2024-06-20T00:00:00.000000000"),
102 ]
103 sd = idd.SingleData([1, 2, 3], index=timeindex)
104 self.assertTrue(
105 sd.index.index(np.datetime64("2024-06-21T00:00:00.000000000"))
106 == sd.index.index(np.datetime64("2024-06-21T00:00:00"))
107 )
108 self.assertTrue(sd.index.index(pd.Timestamp("2024-06-21 00:00")) == 1)
109
110 # Bad case: the input is not aligned
111 timeindex[1] = (np.datetime64("2024-06-21T00:00:00.00"),)
112 with self.assertRaises(TypeError):
113 sd = idd.SingleData([1, 2, 3], index=timeindex)
114
115 def test_ops(self):
116 sd1 = idd.SingleData([1, 2, 3, 4], index=["foo", "bar", "f", "g"])

Callers

nothing calls this directly

Calls 3

isnaMethod · 0.80
replaceMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected