Python pandas.util.testing.makeFloatSeries() Examples

The following are 30 code examples of pandas.util.testing.makeFloatSeries(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.util.testing , or try the search function .
Example #1
Source File: test_generic.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_transpose(self):
        msg = (r"transpose\(\) got multiple values for "
               r"keyword argument 'axes'")
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            # calls implementation in pandas/core/base.py
            tm.assert_series_equal(s.transpose(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.transpose().transpose(), df)

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.transpose(2, 0, 1)
                                      .transpose(1, 2, 0), p)
                with pytest.raises(TypeError, match=msg):
                    p.transpose(2, 0, 1, axes=(2, 0, 1)) 
Example #2
Source File: test_generic.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_numpy_transpose(self):
        msg = "the 'axes' parameter is not supported"

        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.transpose(s), s)

        with pytest.raises(ValueError, match=msg):
            np.transpose(s, axes=1)

        df = tm.makeTimeDataFrame()
        tm.assert_frame_equal(np.transpose(np.transpose(df)), df)

        with pytest.raises(ValueError, match=msg):
            np.transpose(df, axes=1)

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            p = tm.makePanel()
            tm.assert_panel_equal(np.transpose(
                np.transpose(p, axes=(2, 0, 1)),
                axes=(1, 2, 0)), p) 
Example #3
Source File: test_generic.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_take(self):
        indices = [1, 5, -2, 6, 3, -1]
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            out = s.take(indices)
            expected = Series(data=s.values.take(indices),
                              index=s.index.take(indices), dtype=s.dtype)
            tm.assert_series_equal(out, expected)
        for df in [tm.makeTimeDataFrame()]:
            out = df.take(indices)
            expected = DataFrame(data=df.values.take(indices, axis=0),
                                 index=df.index.take(indices),
                                 columns=df.columns)
            tm.assert_frame_equal(out, expected)

        indices = [-3, 2, 0, 1]
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                out = p.take(indices)
                expected = Panel(data=p.values.take(indices, axis=0),
                                 items=p.items.take(indices),
                                 major_axis=p.major_axis,
                                 minor_axis=p.minor_axis)
                tm.assert_panel_equal(out, expected) 
Example #4
Source File: test_generic.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_take(self):
        indices = [1, 5, -2, 6, 3, -1]
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            out = s.take(indices)
            expected = Series(data=s.values.take(indices),
                              index=s.index.take(indices), dtype=s.dtype)
            tm.assert_series_equal(out, expected)
        for df in [tm.makeTimeDataFrame()]:
            out = df.take(indices)
            expected = DataFrame(data=df.values.take(indices, axis=0),
                                 index=df.index.take(indices),
                                 columns=df.columns)
            tm.assert_frame_equal(out, expected)

        indices = [-3, 2, 0, 1]
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                out = p.take(indices)
                expected = Panel(data=p.values.take(indices, axis=0),
                                 items=p.items.take(indices),
                                 major_axis=p.major_axis,
                                 minor_axis=p.minor_axis)
                tm.assert_panel_equal(out, expected) 
Example #5
Source File: test_generic.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_take(self):
        indices = [1, 5, -2, 6, 3, -1]
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            out = s.take(indices)
            expected = Series(data=s.values.take(indices),
                              index=s.index.take(indices), dtype=s.dtype)
            tm.assert_series_equal(out, expected)
        for df in [tm.makeTimeDataFrame()]:
            out = df.take(indices)
            expected = DataFrame(data=df.values.take(indices, axis=0),
                                 index=df.index.take(indices),
                                 columns=df.columns)
            tm.assert_frame_equal(out, expected)

        indices = [-3, 2, 0, 1]
        with catch_warnings(record=True):
            for p in [tm.makePanel()]:
                out = p.take(indices)
                expected = Panel(data=p.values.take(indices, axis=0),
                                 items=p.items.take(indices),
                                 major_axis=p.major_axis,
                                 minor_axis=p.minor_axis)
                tm.assert_panel_equal(out, expected) 
Example #6
Source File: test_generic.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_numpy_transpose(self):
        msg = "the 'axes' parameter is not supported"

        s = tm.makeFloatSeries()
        tm.assert_series_equal(
            np.transpose(s), s)
        tm.assert_raises_regex(ValueError, msg,
                               np.transpose, s, axes=1)

        df = tm.makeTimeDataFrame()
        tm.assert_frame_equal(np.transpose(
            np.transpose(df)), df)
        tm.assert_raises_regex(ValueError, msg,
                               np.transpose, df, axes=1)

        with catch_warnings(record=True):
            p = tm.makePanel()
            tm.assert_panel_equal(np.transpose(
                np.transpose(p, axes=(2, 0, 1)),
                axes=(1, 2, 0)), p) 
Example #7
Source File: test_generic.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_transpose(self):
        msg = (r"transpose\(\) got multiple values for "
               r"keyword argument 'axes'")
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            # calls implementation in pandas/core/base.py
            tm.assert_series_equal(s.transpose(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.transpose().transpose(), df)

        with catch_warnings(record=True):
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.transpose(2, 0, 1)
                                      .transpose(1, 2, 0), p)
                tm.assert_raises_regex(TypeError, msg, p.transpose,
                                       2, 0, 1, axes=(2, 0, 1)) 
Example #8
Source File: test_generic.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_transpose(self):
        msg = (r"transpose\(\) got multiple values for "
               r"keyword argument 'axes'")
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            # calls implementation in pandas/core/base.py
            tm.assert_series_equal(s.transpose(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.transpose().transpose(), df)

        with catch_warnings(record=True):
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.transpose(2, 0, 1)
                                      .transpose(1, 2, 0), p)
                tm.assert_raises_regex(TypeError, msg, p.transpose,
                                       2, 0, 1, axes=(2, 0, 1)) 
Example #9
Source File: test_generic.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_numpy_transpose(self):
        msg = "the 'axes' parameter is not supported"

        s = tm.makeFloatSeries()
        tm.assert_series_equal(
            np.transpose(s), s)
        tm.assert_raises_regex(ValueError, msg,
                               np.transpose, s, axes=1)

        df = tm.makeTimeDataFrame()
        tm.assert_frame_equal(np.transpose(
            np.transpose(df)), df)
        tm.assert_raises_regex(ValueError, msg,
                               np.transpose, df, axes=1)

        with catch_warnings(record=True):
            p = tm.makePanel()
            tm.assert_panel_equal(np.transpose(
                np.transpose(p, axes=(2, 0, 1)),
                axes=(1, 2, 0)), p) 
Example #10
Source File: test_generic.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_take(self):
        indices = [1, 5, -2, 6, 3, -1]
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            out = s.take(indices)
            expected = Series(data=s.values.take(indices),
                              index=s.index.take(indices), dtype=s.dtype)
            tm.assert_series_equal(out, expected)
        for df in [tm.makeTimeDataFrame()]:
            out = df.take(indices)
            expected = DataFrame(data=df.values.take(indices, axis=0),
                                 index=df.index.take(indices),
                                 columns=df.columns)
            tm.assert_frame_equal(out, expected)

        indices = [-3, 2, 0, 1]
        with catch_warnings(record=True):
            for p in [tm.makePanel()]:
                out = p.take(indices)
                expected = Panel(data=p.values.take(indices, axis=0),
                                 items=p.items.take(indices),
                                 major_axis=p.major_axis,
                                 minor_axis=p.minor_axis)
                tm.assert_panel_equal(out, expected) 
Example #11
Source File: test_generic.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_numpy_transpose(self):
        msg = "the 'axes' parameter is not supported"

        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.transpose(s), s)

        with pytest.raises(ValueError, match=msg):
            np.transpose(s, axes=1)

        df = tm.makeTimeDataFrame()
        tm.assert_frame_equal(np.transpose(np.transpose(df)), df)

        with pytest.raises(ValueError, match=msg):
            np.transpose(df, axes=1)

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            p = tm.makePanel()
            tm.assert_panel_equal(np.transpose(
                np.transpose(p, axes=(2, 0, 1)),
                axes=(1, 2, 0)), p) 
Example #12
Source File: test_generic.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_transpose(self):
        msg = (r"transpose\(\) got multiple values for "
               r"keyword argument 'axes'")
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            # calls implementation in pandas/core/base.py
            tm.assert_series_equal(s.transpose(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.transpose().transpose(), df)

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.transpose(2, 0, 1)
                                      .transpose(1, 2, 0), p)
                with pytest.raises(TypeError, match=msg):
                    p.transpose(2, 0, 1, axes=(2, 0, 1)) 
Example #13
Source File: test_missing.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected) 
Example #14
Source File: test_generic.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_numpy_squeeze(self):
        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.squeeze(s), s)

        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(np.squeeze(df), df['A']) 
Example #15
Source File: test_operators.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_op_method(self):
        def check(series, other, check_reverse=False):
            simple_ops = ['add', 'sub', 'mul', 'floordiv', 'truediv', 'pow']
            if not compat.PY3:
                simple_ops.append('div')

            for opname in simple_ops:
                op = getattr(Series, opname)

                if op == 'div':
                    alt = operator.truediv
                else:
                    alt = getattr(operator, opname)

                result = op(series, other)
                expected = alt(series, other)
                assert_almost_equal(result, expected)
                if check_reverse:
                    rop = getattr(Series, "r" + opname)
                    result = rop(series, other)
                    expected = alt(other, series)
                    assert_almost_equal(result, expected)

        check(self.ts, self.ts * 2)
        check(self.ts, self.ts[::2])
        check(self.ts, 5, check_reverse=True)
        check(tm.makeFloatSeries(), tm.makeFloatSeries(), check_reverse=True) 
Example #16
Source File: test_missing.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_notna_notnull(notna_f):
    assert notna_f(1.)
    assert not notna_f(None)
    assert not notna_f(np.NaN)

    with cf.option_context("mode.use_inf_as_na", False):
        assert notna_f(np.inf)
        assert notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.all()

    with cf.option_context("mode.use_inf_as_na", True):
        assert not notna_f(np.inf)
        assert not notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.sum() == 2

    with cf.option_context("mode.use_inf_as_na", False):
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert (isinstance(notna_f(s), Series)) 
Example #17
Source File: test_missing.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected)

        # panel 4d
        with catch_warnings(record=True):
            for p in [tm.makePanel4D(), tm.add_nans_panel4d(tm.makePanel4D())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel4d_equal(result, expected) 
Example #18
Source File: test_generic.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_numpy_squeeze(self):
        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.squeeze(s), s)

        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(np.squeeze(df), df['A']) 
Example #19
Source File: test_missing.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_notna_notnull(notna_f):
    assert notna_f(1.)
    assert not notna_f(None)
    assert not notna_f(np.NaN)

    with cf.option_context("mode.use_inf_as_na", False):
        assert notna_f(np.inf)
        assert notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.all()

    with cf.option_context("mode.use_inf_as_na", True):
        assert not notna_f(np.inf)
        assert not notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.sum() == 2

    with cf.option_context("mode.use_inf_as_na", False):
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert (isinstance(notna_f(s), Series)) 
Example #20
Source File: test_missing.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected) 
Example #21
Source File: test_missing.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_notna_notnull(notna_f):
    assert notna_f(1.)
    assert not notna_f(None)
    assert not notna_f(np.NaN)

    with cf.option_context("mode.use_inf_as_na", False):
        assert notna_f(np.inf)
        assert notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.all()

    with cf.option_context("mode.use_inf_as_na", True):
        assert not notna_f(np.inf)
        assert not notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.sum() == 2

    with cf.option_context("mode.use_inf_as_na", False):
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert (isinstance(notna_f(s), Series)) 
Example #22
Source File: test_missing.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected) 
Example #23
Source File: test_missing.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_notna_notnull(notna_f):
    assert notna_f(1.)
    assert not notna_f(None)
    assert not notna_f(np.NaN)

    with cf.option_context("mode.use_inf_as_na", False):
        assert notna_f(np.inf)
        assert notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.all()

    with cf.option_context("mode.use_inf_as_na", True):
        assert not notna_f(np.inf)
        assert not notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.sum() == 2

    with cf.option_context("mode.use_inf_as_na", False):
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert (isinstance(notna_f(s), Series)) 
Example #24
Source File: test_generic.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_numpy_squeeze(self):
        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.squeeze(s), s)

        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(np.squeeze(df), df['A']) 
Example #25
Source File: test_missing.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected) 
Example #26
Source File: test_missing.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_notna_notnull(notna_f):
    assert notna_f(1.)
    assert not notna_f(None)
    assert not notna_f(np.NaN)

    with cf.option_context("mode.use_inf_as_na", False):
        assert notna_f(np.inf)
        assert notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.all()

    with cf.option_context("mode.use_inf_as_na", True):
        assert not notna_f(np.inf)
        assert not notna_f(-np.inf)

        arr = np.array([1.5, np.inf, 3.5, -np.inf])
        result = notna_f(arr)
        assert result.sum() == 2

    with cf.option_context("mode.use_inf_as_na", False):
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert (isinstance(notna_f(s), Series)) 
Example #27
Source File: test_generic.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_numpy_squeeze(self):
        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.squeeze(s), s)

        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(np.squeeze(df), df['A']) 
Example #28
Source File: test_generic.py    From recruit with Apache License 2.0 4 votes vote down vote up
def test_squeeze(self):
        # noop
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            tm.assert_series_equal(s.squeeze(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.squeeze(), df)
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.squeeze(), p)

        # squeezing
        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(df.squeeze(), df['A'])

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            p = tm.makePanel().reindex(items=['ItemA'])
            tm.assert_frame_equal(p.squeeze(), p['ItemA'])

            p = tm.makePanel().reindex(items=['ItemA'], minor_axis=['A'])
            tm.assert_series_equal(p.squeeze(), p.loc['ItemA', :, 'A'])

        # don't fail with 0 length dimensions GH11229 & GH8999
        empty_series = Series([], name='five')
        empty_frame = DataFrame([empty_series])
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            empty_panel = Panel({'six': empty_frame})

        [tm.assert_series_equal(empty_series, higher_dim.squeeze())
         for higher_dim in [empty_series, empty_frame, empty_panel]]

        # axis argument
        df = tm.makeTimeDataFrame(nper=1).iloc[:, :1]
        assert df.shape == (1, 1)
        tm.assert_series_equal(df.squeeze(axis=0), df.iloc[0])
        tm.assert_series_equal(df.squeeze(axis='index'), df.iloc[0])
        tm.assert_series_equal(df.squeeze(axis=1), df.iloc[:, 0])
        tm.assert_series_equal(df.squeeze(axis='columns'), df.iloc[:, 0])
        assert df.squeeze() == df.iloc[0, 0]
        pytest.raises(ValueError, df.squeeze, axis=2)
        pytest.raises(ValueError, df.squeeze, axis='x')

        df = tm.makeTimeDataFrame(3)
        tm.assert_frame_equal(df.squeeze(axis=0), df) 
Example #29
Source File: test_generic.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 4 votes vote down vote up
def test_squeeze(self):
        # noop
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            tm.assert_series_equal(s.squeeze(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.squeeze(), df)
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.squeeze(), p)

        # squeezing
        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(df.squeeze(), df['A'])

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            p = tm.makePanel().reindex(items=['ItemA'])
            tm.assert_frame_equal(p.squeeze(), p['ItemA'])

            p = tm.makePanel().reindex(items=['ItemA'], minor_axis=['A'])
            tm.assert_series_equal(p.squeeze(), p.loc['ItemA', :, 'A'])

        # don't fail with 0 length dimensions GH11229 & GH8999
        empty_series = Series([], name='five')
        empty_frame = DataFrame([empty_series])
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            empty_panel = Panel({'six': empty_frame})

        [tm.assert_series_equal(empty_series, higher_dim.squeeze())
         for higher_dim in [empty_series, empty_frame, empty_panel]]

        # axis argument
        df = tm.makeTimeDataFrame(nper=1).iloc[:, :1]
        assert df.shape == (1, 1)
        tm.assert_series_equal(df.squeeze(axis=0), df.iloc[0])
        tm.assert_series_equal(df.squeeze(axis='index'), df.iloc[0])
        tm.assert_series_equal(df.squeeze(axis=1), df.iloc[:, 0])
        tm.assert_series_equal(df.squeeze(axis='columns'), df.iloc[:, 0])
        assert df.squeeze() == df.iloc[0, 0]
        pytest.raises(ValueError, df.squeeze, axis=2)
        pytest.raises(ValueError, df.squeeze, axis='x')

        df = tm.makeTimeDataFrame(3)
        tm.assert_frame_equal(df.squeeze(axis=0), df) 
Example #30
Source File: test_generic.py    From twitter-stock-recommendation with MIT License 4 votes vote down vote up
def test_squeeze(self):
        # noop
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            tm.assert_series_equal(s.squeeze(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.squeeze(), df)
        with catch_warnings(record=True):
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.squeeze(), p)

        # squeezing
        df = tm.makeTimeDataFrame().reindex(columns=['A'])
        tm.assert_series_equal(df.squeeze(), df['A'])

        with catch_warnings(record=True):
            p = tm.makePanel().reindex(items=['ItemA'])
            tm.assert_frame_equal(p.squeeze(), p['ItemA'])

            p = tm.makePanel().reindex(items=['ItemA'], minor_axis=['A'])
            tm.assert_series_equal(p.squeeze(), p.loc['ItemA', :, 'A'])

        # don't fail with 0 length dimensions GH11229 & GH8999
        empty_series = Series([], name='five')
        empty_frame = DataFrame([empty_series])
        with catch_warnings(record=True):
            empty_panel = Panel({'six': empty_frame})

        [tm.assert_series_equal(empty_series, higher_dim.squeeze())
         for higher_dim in [empty_series, empty_frame, empty_panel]]

        # axis argument
        df = tm.makeTimeDataFrame(nper=1).iloc[:, :1]
        assert df.shape == (1, 1)
        tm.assert_series_equal(df.squeeze(axis=0), df.iloc[0])
        tm.assert_series_equal(df.squeeze(axis='index'), df.iloc[0])
        tm.assert_series_equal(df.squeeze(axis=1), df.iloc[:, 0])
        tm.assert_series_equal(df.squeeze(axis='columns'), df.iloc[:, 0])
        assert df.squeeze() == df.iloc[0, 0]
        pytest.raises(ValueError, df.squeeze, axis=2)
        pytest.raises(ValueError, df.squeeze, axis='x')

        df = tm.makeTimeDataFrame(3)
        tm.assert_frame_equal(df.squeeze(axis=0), df)