Ejemplo n.º 1
0
 def testEqual1(self) -> None:
     df0 = pd.DataFrame([[0, 1, 0], [2, 3, 60], [4, 5, 120]],
                        columns=['A', 'B', 'C'])
     ds0 = SimpleSeries.fromDataFrame(df0)
     ds1 = SimpleSeries.fromDataFrame(df0)
     self.assertTrue(ds0 == ds1)
     buf = ds1.iat[0, 0]
     ds1.iat[0, 0] = -1
     self.assertFalse(ds0 == ds1)
     ds1.iat[0, 0] = buf
     self.assertFalse(ds0 != ds1)
Ejemplo n.º 2
0
 def testCreateNumericIndex0(self) -> None:
     r0 = SimpleSeries.createNumericIndex(0.9, 40, 0.1)
     r1 = SimpleSeries.createNumericIndex(10, 40, 1)
     r2 = SimpleSeries.createNumericIndex(10, 40, 10)
     r3 = SimpleSeries.createNumericIndex(10, 40, 100)
     self.assertEqual(len(r0), 392)
     self.assertAlmostEqual(r0[-2], 39.9, 1)
     self.assertEqual(len(r1), 31)
     self.assertEqual(r1[-2], 39)
     self.assertEqual(len(r2), 4)
     self.assertEqual(r2[-2], 30)
     self.assertEqual(len(r3), 1)
     self.assertEqual(r3[0], 10)
Ejemplo n.º 3
0
 def testRandom0(self) -> None:
     #tests also __setitem__
     min = 0.000001
     max = 0.000005
     ds = SimpleSeries.random(min, max, 10, ['A', 'B', 'Cr'])
     ds[1, 1] = 1
     self.assertFalse(ds.bounded(min, max))
Ejemplo n.º 4
0
 def testColumnNames0(self) -> None:
     columnsNames = ['A', 'B', 'C']
     numColumnsNames = ['A']
     df0 = pd.DataFrame([[0, 1, 'A'], [2, 3, 'B'], [4, 'x', 'C']],
                        columns=columnsNames)
     ds0 = SimpleSeries.fromDataFrame(df0)
     self.assertTrue(all(ds0.columnNames() == columnsNames))
     self.assertTrue(all(ds0.numericColumnNames() == numColumnsNames))
Ejemplo n.º 5
0
 def testBounded0(self) -> None:
     df0 = pd.DataFrame([[0, 1, 10.23], [2, 3, -23.1], [4, 5, 9]],
                        columns=['A', 'B', 'C'])
     ds0 = SimpleSeries.fromDataFrame(df0)
     self.assertTrue(ds0.bounded(-23.1, 10.23))
     self.assertFalse(ds0.bounded(-23.0, 10.23))
     self.assertFalse(ds0.bounded(-23.2, 10.0))
     self.assertFalse(ds0.bounded(-22, 10.0))
Ejemplo n.º 6
0
 def testFindExpectedSamples0(self) -> Any:
     df0 = pd.DataFrame(
         [[10, 1, 0], [20, 3, 60], [30, 5, 120], [40, 8, 20], [50, 5, 10]],
         columns=['i', 'A', 'B'])
     df0 = df0.set_index('i')
     ds0 = SimpleSeries.fromDataFrame(df0)
     self.assertEqual(ds0.findExpectedSamples(0.1), 401)
     self.assertEqual(ds0.findExpectedSamples(1), 41)
     self.assertEqual(ds0.findExpectedSamples(10), 5)
     self.assertEqual(ds0.findExpectedSamples(100), 1)
     ds1 = ds0.reversed()
     self.assertEqual(ds1.findExpectedSamples(0.1), 401)
Ejemplo n.º 7
0
    def testInterpolate0(self) -> None:
        resolution = 0.1
        ds0 = SimpleSeries.random(0.1, 0.3, 5, ['A', 'B'])
        expectedSamples, existingSamples = ds0.findMissing(resolution)
        self.assertTrue(ds0.hasMissing(resolution))
        self.assertEqual(existingSamples, 5)
        self.assertEqual(expectedSamples, 41)
        self.assertEqual(expectedSamples - existingSamples, 36)

        ds1 = ds0.copy()
        ds1.interpolate(resolution)
        expectedSamples, existingSamples = ds1.findMissing(resolution)
        self.assertFalse(ds1.hasMissing(resolution))
        self.assertEqual(existingSamples, 41)
        self.assertEqual(expectedSamples, 41)

        if plot:
            plt.subplot(1, 2, 1)
            plt.plot(ds0.toDataFrame())
            plt.subplot(1, 2, 2)
            plt.plot(ds1.toDataFrame())
            plt.show()
Ejemplo n.º 8
0
 def setUpClass(cls) -> None:
     #code to be executed only once before all tests start
     #Get market data
     cls.marketDataSS = SimpleSeries.fromCSV(seriesFN, allColumNames)
Ejemplo n.º 9
0
 def testRandom1(self) -> None:
     min = -10.000001
     max = 0.000005
     ds = SimpleSeries.random(min, max, 10, ['A', 'B', 'Cr'])
     self.assertTrue(ds.bounded(min, max))