Python pandas.util.testing.makePeriodSeries() Examples
The following are 28
code examples of pandas.util.testing.makePeriodSeries().
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_missing.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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 #2
Source File: test_missing.py From twitter-stock-recommendation with MIT License | 5 votes |
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 #3
Source File: test_missing.py From twitter-stock-recommendation with MIT License | 5 votes |
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 #4
Source File: test_timeseries.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_tshift(self): # PeriodIndex ps = tm.makePeriodSeries() shifted = ps.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(unshifted, ps) shifted2 = ps.tshift(freq='B') assert_series_equal(shifted, shifted2) shifted3 = ps.tshift(freq=BDay()) assert_series_equal(shifted, shifted3) pytest.raises(ValueError, ps.tshift, freq='M') # DatetimeIndex shifted = self.ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(self.ts, unshifted) shifted2 = self.ts.tshift(freq=self.ts.index.freq) assert_series_equal(shifted, shifted2) inferred_ts = Series(self.ts.values, Index(np.asarray(self.ts.index)), name='ts') shifted = inferred_ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(shifted, self.ts.tshift(1)) assert_series_equal(unshifted, inferred_ts) no_freq = self.ts[[0, 5, 7]] pytest.raises(ValueError, no_freq.tshift)
Example #5
Source File: test_datetimelike.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_business_freq(self): bts = tm.makePeriodSeries() _, ax = self.plt.subplots() bts.plot(ax=ax) assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].ordinal idx = ax.get_lines()[0].get_xdata() assert PeriodIndex(data=idx).freqstr == 'B'
Example #6
Source File: test_series.py From twitter-stock-recommendation with MIT License | 5 votes |
def setup_method(self, method): TestPlotBase.setup_method(self, method) import matplotlib as mpl mpl.rcdefaults() self.ts = tm.makeTimeSeries() self.ts.name = 'ts' self.series = tm.makeStringSeries() self.series.name = 'series' self.iseries = tm.makePeriodSeries() self.iseries.name = 'iseries'
Example #7
Source File: test_datetimelike.py From coffeegrindsize with MIT License | 5 votes |
def test_business_freq(self): bts = tm.makePeriodSeries() _, ax = self.plt.subplots() bts.plot(ax=ax) assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].ordinal idx = ax.get_lines()[0].get_xdata() assert PeriodIndex(data=idx).freqstr == 'B'
Example #8
Source File: test_series.py From coffeegrindsize with MIT License | 5 votes |
def setup_method(self, method): TestPlotBase.setup_method(self, method) import matplotlib as mpl mpl.rcdefaults() self.ts = tm.makeTimeSeries() self.ts.name = 'ts' self.series = tm.makeStringSeries() self.series.name = 'series' self.iseries = tm.makePeriodSeries() self.iseries.name = 'iseries'
Example #9
Source File: test_missing.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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 #10
Source File: test_missing.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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 #11
Source File: test_timeseries.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_tshift(self): # PeriodIndex ps = tm.makePeriodSeries() shifted = ps.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(unshifted, ps) shifted2 = ps.tshift(freq='B') assert_series_equal(shifted, shifted2) shifted3 = ps.tshift(freq=BDay()) assert_series_equal(shifted, shifted3) pytest.raises(ValueError, ps.tshift, freq='M') # DatetimeIndex shifted = self.ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(self.ts, unshifted) shifted2 = self.ts.tshift(freq=self.ts.index.freq) assert_series_equal(shifted, shifted2) inferred_ts = Series(self.ts.values, Index(np.asarray(self.ts.index)), name='ts') shifted = inferred_ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(shifted, self.ts.tshift(1)) assert_series_equal(unshifted, inferred_ts) no_freq = self.ts[[0, 5, 7]] pytest.raises(ValueError, no_freq.tshift)
Example #12
Source File: test_datetimelike.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_business_freq(self): bts = tm.makePeriodSeries() _, ax = self.plt.subplots() bts.plot(ax=ax) assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].ordinal idx = ax.get_lines()[0].get_xdata() assert PeriodIndex(data=idx).freqstr == 'B'
Example #13
Source File: test_series.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def setup_method(self, method): TestPlotBase.setup_method(self, method) import matplotlib as mpl mpl.rcdefaults() self.ts = tm.makeTimeSeries() self.ts.name = 'ts' self.series = tm.makeStringSeries() self.series.name = 'series' self.iseries = tm.makePeriodSeries() self.iseries.name = 'iseries'
Example #14
Source File: test_missing.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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 #15
Source File: test_series.py From recruit with Apache License 2.0 | 5 votes |
def setup_method(self, method): TestPlotBase.setup_method(self, method) import matplotlib as mpl mpl.rcdefaults() self.ts = tm.makeTimeSeries() self.ts.name = 'ts' self.series = tm.makeStringSeries() self.series.name = 'series' self.iseries = tm.makePeriodSeries() self.iseries.name = 'iseries'
Example #16
Source File: test_timeseries.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_tshift(self): # PeriodIndex ps = tm.makePeriodSeries() shifted = ps.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(unshifted, ps) shifted2 = ps.tshift(freq='B') assert_series_equal(shifted, shifted2) shifted3 = ps.tshift(freq=BDay()) assert_series_equal(shifted, shifted3) msg = "Given freq M does not match PeriodIndex freq B" with pytest.raises(ValueError, match=msg): ps.tshift(freq='M') # DatetimeIndex shifted = self.ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(self.ts, unshifted) shifted2 = self.ts.tshift(freq=self.ts.index.freq) assert_series_equal(shifted, shifted2) inferred_ts = Series(self.ts.values, Index(np.asarray(self.ts.index)), name='ts') shifted = inferred_ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(shifted, self.ts.tshift(1)) assert_series_equal(unshifted, inferred_ts) no_freq = self.ts[[0, 5, 7]] msg = "Freq was not given and was not set in the index" with pytest.raises(ValueError, match=msg): no_freq.tshift()
Example #17
Source File: test_datetimelike.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_business_freq(self): bts = tm.makePeriodSeries() _, ax = self.plt.subplots() bts.plot(ax=ax) assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].ordinal idx = ax.get_lines()[0].get_xdata() assert PeriodIndex(data=idx).freqstr == 'B'
Example #18
Source File: test_series.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def setup_method(self, method): TestPlotBase.setup_method(self, method) import matplotlib as mpl mpl.rcdefaults() self.ts = tm.makeTimeSeries() self.ts.name = 'ts' self.series = tm.makeStringSeries() self.series.name = 'series' self.iseries = tm.makePeriodSeries() self.iseries.name = 'iseries'
Example #19
Source File: test_plotting.py From Computable with MIT License | 5 votes |
def test_business_freq(self): import matplotlib.pyplot as plt bts = tm.makePeriodSeries() ax = bts.plot() self.assertEqual(ax.get_lines()[0].get_xydata()[0, 0], bts.index[0].ordinal) idx = ax.get_lines()[0].get_xdata() self.assertEqual(PeriodIndex(data=idx).freqstr, 'B')
Example #20
Source File: test_missing.py From vnpy_crypto with MIT License | 5 votes |
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 vnpy_crypto with MIT License | 5 votes |
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_timeseries.py From vnpy_crypto with MIT License | 5 votes |
def test_tshift(self): # PeriodIndex ps = tm.makePeriodSeries() shifted = ps.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(unshifted, ps) shifted2 = ps.tshift(freq='B') assert_series_equal(shifted, shifted2) shifted3 = ps.tshift(freq=BDay()) assert_series_equal(shifted, shifted3) pytest.raises(ValueError, ps.tshift, freq='M') # DatetimeIndex shifted = self.ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(self.ts, unshifted) shifted2 = self.ts.tshift(freq=self.ts.index.freq) assert_series_equal(shifted, shifted2) inferred_ts = Series(self.ts.values, Index(np.asarray(self.ts.index)), name='ts') shifted = inferred_ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(shifted, self.ts.tshift(1)) assert_series_equal(unshifted, inferred_ts) no_freq = self.ts[[0, 5, 7]] pytest.raises(ValueError, no_freq.tshift)
Example #23
Source File: test_datetimelike.py From vnpy_crypto with MIT License | 5 votes |
def test_business_freq(self): bts = tm.makePeriodSeries() _, ax = self.plt.subplots() bts.plot(ax=ax) assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].ordinal idx = ax.get_lines()[0].get_xdata() assert PeriodIndex(data=idx).freqstr == 'B'
Example #24
Source File: test_series.py From vnpy_crypto with MIT License | 5 votes |
def setup_method(self, method): TestPlotBase.setup_method(self, method) import matplotlib as mpl mpl.rcdefaults() self.ts = tm.makeTimeSeries() self.ts.name = 'ts' self.series = tm.makeStringSeries() self.series.name = 'series' self.iseries = tm.makePeriodSeries() self.iseries.name = 'iseries'
Example #25
Source File: test_missing.py From recruit with Apache License 2.0 | 5 votes |
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 |
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_timeseries.py From recruit with Apache License 2.0 | 5 votes |
def test_tshift(self): # PeriodIndex ps = tm.makePeriodSeries() shifted = ps.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(unshifted, ps) shifted2 = ps.tshift(freq='B') assert_series_equal(shifted, shifted2) shifted3 = ps.tshift(freq=BDay()) assert_series_equal(shifted, shifted3) msg = "Given freq M does not match PeriodIndex freq B" with pytest.raises(ValueError, match=msg): ps.tshift(freq='M') # DatetimeIndex shifted = self.ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(self.ts, unshifted) shifted2 = self.ts.tshift(freq=self.ts.index.freq) assert_series_equal(shifted, shifted2) inferred_ts = Series(self.ts.values, Index(np.asarray(self.ts.index)), name='ts') shifted = inferred_ts.tshift(1) unshifted = shifted.tshift(-1) assert_series_equal(shifted, self.ts.tshift(1)) assert_series_equal(unshifted, inferred_ts) no_freq = self.ts[[0, 5, 7]] msg = "Freq was not given and was not set in the index" with pytest.raises(ValueError, match=msg): no_freq.tshift()
Example #28
Source File: test_datetimelike.py From recruit with Apache License 2.0 | 5 votes |
def test_business_freq(self): bts = tm.makePeriodSeries() _, ax = self.plt.subplots() bts.plot(ax=ax) assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].ordinal idx = ax.get_lines()[0].get_xdata() assert PeriodIndex(data=idx).freqstr == 'B'