Example #1
0
 def test_diff_axis(self):
     # GH 9727
     df = DataFrame([[1., 2.], [3., 4.]])
     assert_frame_equal(df.diff(axis=1), DataFrame(
         [[np.nan, 1.], [np.nan, 1.]]))
     assert_frame_equal(df.diff(axis=0), DataFrame(
         [[np.nan, np.nan], [2., 2.]]))
Example #2
0
 def test_diff_datetime_axis1(self, tz):
     # GH 18578
     df = DataFrame({0: date_range('2010', freq='D', periods=2, tz=tz),
                     1: date_range('2010', freq='D', periods=2, tz=tz)})
     if tz is None:
         result = df.diff(axis=1)
         expected = DataFrame({0: pd.TimedeltaIndex(['NaT', 'NaT']),
                               1: pd.TimedeltaIndex(['0 days',
                                                     '0 days'])})
         assert_frame_equal(result, expected)
     else:
         with pytest.raises(NotImplementedError):
             result = df.diff(axis=1)
Example #3
0
    def test_diff_timedelta(self):
        # GH 4533
        df = DataFrame(dict(time=[Timestamp("20130101 9:01"), Timestamp("20130101 9:02")], value=[1.0, 2.0]))

        res = df.diff()
        exp = DataFrame([[pd.NaT, np.nan], [pd.Timedelta("00:01:00"), 1]], columns=["time", "value"])
        assert_frame_equal(res, exp)
Example #4
0
    def test_diff_datetime_axis0(self, tz):
        # GH 18578
        df = DataFrame({0: date_range('2010', freq='D', periods=2, tz=tz),
                        1: date_range('2010', freq='D', periods=2, tz=tz)})

        result = df.diff(axis=0)
        expected = DataFrame({0: pd.TimedeltaIndex(['NaT', '1 days']),
                              1: pd.TimedeltaIndex(['NaT', '1 days'])})
        assert_frame_equal(result, expected)
Example #5
0
    def test_diff_timedelta(self):
        # GH 4533
        df = DataFrame(dict(time=[Timestamp('20130101 9:01'),
                                  Timestamp('20130101 9:02')],
                            value=[1.0, 2.0]))

        res = df.diff()
        exp = DataFrame([[pd.NaT, np.nan],
                         [pd.Timedelta('00:01:00'), 1]],
                        columns=['time', 'value'])
        assert_frame_equal(res, exp)
Example #6
0
    def test_diff_mixed_dtype(self):
        df = DataFrame(np.random.randn(5, 3))
        df['A'] = np.array([1, 2, 3, 4, 5], dtype=object)

        result = df.diff()
        self.assertEqual(result[0].dtype, np.float64)