Python pandas.Float64Index() Examples
The following are 30
code examples of pandas.Float64Index().
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
, or try the search function
.
Example #1
Source File: test_range.py From recruit with Apache License 2.0 | 7 votes |
def test_explicit_conversions(self): # GH 8608 # add/sub are overridden explicitly for Float/Int Index idx = RangeIndex(5) # float conversions arr = np.arange(5, dtype='int64') * 3.2 expected = Float64Index(arr) fidx = idx * 3.2 tm.assert_index_equal(fidx, expected) fidx = 3.2 * idx tm.assert_index_equal(fidx, expected) # interops with numpy arrays expected = Float64Index(arr) a = np.zeros(5, dtype='float64') result = fidx - a tm.assert_index_equal(result, expected) expected = Float64Index(-arr) a = np.zeros(5, dtype='float64') result = a - fidx tm.assert_index_equal(result, expected)
Example #2
Source File: test_numeric.py From vnpy_crypto with MIT License | 6 votes |
def test_get_nan_multiple(): # GH 8569 # ensure that fixing "test_get_nan" above hasn't broken get # with multiple elements s = pd.Float64Index(range(10)).to_series() idx = [2, 30] with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert_series_equal(s.get(idx), Series([2, np.nan], index=idx)) idx = [2, np.nan] with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert_series_equal(s.get(idx), Series([2, np.nan], index=idx)) # GH 17295 - all missing keys idx = [20, 30] assert(s.get(idx) is None) idx = [np.nan, np.nan] assert(s.get(idx) is None)
Example #3
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_get_nan_multiple(): # GH 8569 # ensure that fixing "test_get_nan" above hasn't broken get # with multiple elements s = pd.Float64Index(range(10)).to_series() idx = [2, 30] with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert_series_equal(s.get(idx), Series([2, np.nan], index=idx)) idx = [2, np.nan] with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert_series_equal(s.get(idx), Series([2, np.nan], index=idx)) # GH 17295 - all missing keys idx = [20, 30] assert(s.get(idx) is None) idx = [np.nan, np.nan] assert(s.get(idx) is None)
Example #4
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_explicit_conversions(self): # GH 8608 # add/sub are overridden explicitly for Float/Int Index idx = self._holder(np.arange(5, dtype='int64')) # float conversions arr = np.arange(5, dtype='int64') * 3.2 expected = Float64Index(arr) fidx = idx * 3.2 tm.assert_index_equal(fidx, expected) fidx = 3.2 * idx tm.assert_index_equal(fidx, expected) # interops with numpy arrays expected = Float64Index(arr) a = np.zeros(5, dtype='float64') result = fidx - a tm.assert_index_equal(result, expected) expected = Float64Index(-arr) a = np.zeros(5, dtype='float64') result = a - fidx tm.assert_index_equal(result, expected)
Example #5
Source File: test_numeric.py From vnpy_crypto with MIT License | 6 votes |
def test_explicit_conversions(self): # GH 8608 # add/sub are overridden explicitly for Float/Int Index idx = self._holder(np.arange(5, dtype='int64')) # float conversions arr = np.arange(5, dtype='int64') * 3.2 expected = Float64Index(arr) fidx = idx * 3.2 tm.assert_index_equal(fidx, expected) fidx = 3.2 * idx tm.assert_index_equal(fidx, expected) # interops with numpy arrays expected = Float64Index(arr) a = np.zeros(5, dtype='float64') result = fidx - a tm.assert_index_equal(result, expected) expected = Float64Index(-arr) a = np.zeros(5, dtype='float64') result = a - fidx tm.assert_index_equal(result, expected)
Example #6
Source File: test_scalar_compat.py From vnpy_crypto with MIT License | 5 votes |
def test_minute(self): dr = date_range(start=Timestamp('2000-02-27'), periods=5, freq='T') r1 = pd.Index([x.to_julian_date() for x in dr]) r2 = dr.to_julian_date() assert isinstance(r2, pd.Float64Index) tm.assert_index_equal(r1, r2)
Example #7
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def check_is_index(self, i): assert isinstance(i, Index) assert not isinstance(i, Float64Index)
Example #8
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def check_coerce(self, a, b, is_float_index=True): assert a.equals(b) tm.assert_index_equal(a, b, exact=False) if is_float_index: assert isinstance(b, Float64Index) else: self.check_is_index(b)
Example #9
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_constructor_invalid(self): # invalid pytest.raises(TypeError, Float64Index, 0.) pytest.raises(TypeError, Float64Index, ['a', 'b', 0.]) pytest.raises(TypeError, Float64Index, [Timestamp('20130101')])
Example #10
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_equals_numeric(self): i = Float64Index([1.0, 2.0]) assert i.equals(i) assert i.identical(i) i2 = Float64Index([1.0, 2.0]) assert i.equals(i2) i = Float64Index([1.0, np.nan]) assert i.equals(i) assert i.identical(i) i2 = Float64Index([1.0, np.nan]) assert i.equals(i2)
Example #11
Source File: test_coercion.py From vnpy_crypto with MIT License | 5 votes |
def test_insert_index_float64(self, insert, coerced_val, coerced_dtype): obj = pd.Float64Index([1., 2., 3., 4.]) assert obj.dtype == np.float64 exp = pd.Index([1., coerced_val, 2., 3., 4.]) self._assert_insert_conversion(obj, insert, exp, coerced_dtype)
Example #12
Source File: test_scalar_compat.py From vnpy_crypto with MIT License | 5 votes |
def test_1700(self): dr = date_range(start=Timestamp('1710-10-01'), periods=5, freq='D') r1 = pd.Index([x.to_julian_date() for x in dr]) r2 = dr.to_julian_date() assert isinstance(r2, pd.Float64Index) tm.assert_index_equal(r1, r2)
Example #13
Source File: test_scalar_compat.py From vnpy_crypto with MIT License | 5 votes |
def test_2000(self): dr = date_range(start=Timestamp('2000-02-27'), periods=5, freq='D') r1 = pd.Index([x.to_julian_date() for x in dr]) r2 = dr.to_julian_date() assert isinstance(r2, pd.Float64Index) tm.assert_index_equal(r1, r2)
Example #14
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_insert(self): # GH 18295 (test missing) expected = Float64Index([0, np.nan, 1, 2, 3, 4]) for na in (np.nan, pd.NaT, None): result = self.create_index().insert(1, na) tm.assert_index_equal(result, expected)
Example #15
Source File: test_scalar_compat.py From vnpy_crypto with MIT License | 5 votes |
def test_second(self): dr = date_range(start=Timestamp('2000-02-27'), periods=5, freq='S') r1 = pd.Index([x.to_julian_date() for x in dr]) r2 = dr.to_julian_date() assert isinstance(r2, pd.Float64Index) tm.assert_index_equal(r1, r2)
Example #16
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_get(): # GH 6383 s = Series(np.array([43, 48, 60, 48, 50, 51, 50, 45, 57, 48, 56, 45, 51, 39, 55, 43, 54, 52, 51, 54])) result = s.get(25, 0) expected = 0 assert result == expected s = Series(np.array([43, 48, 60, 48, 50, 51, 50, 45, 57, 48, 56, 45, 51, 39, 55, 43, 54, 52, 51, 54]), index=pd.Float64Index( [25.0, 36.0, 49.0, 64.0, 81.0, 100.0, 121.0, 144.0, 169.0, 196.0, 1225.0, 1296.0, 1369.0, 1444.0, 1521.0, 1600.0, 1681.0, 1764.0, 1849.0, 1936.0], dtype='object')) result = s.get(25, 0) expected = 43 assert result == expected # GH 7407 # with a boolean accessor df = pd.DataFrame({'i': [0] * 3, 'b': [False] * 3}) vc = df.i.value_counts() result = vc.get(99, default='Missing') assert result == 'Missing' vc = df.b.value_counts() result = vc.get(False, default='Missing') assert result == 3 result = vc.get(True, default='Missing') assert result == 'Missing'
Example #17
Source File: test_generic.py From vnpy_crypto with MIT License | 5 votes |
def test_abc_types(self): assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndex) assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCInt64Index) assert isinstance(pd.UInt64Index([1, 2, 3]), gt.ABCUInt64Index) assert isinstance(pd.Float64Index([1, 2, 3]), gt.ABCFloat64Index) assert isinstance(self.multi_index, gt.ABCMultiIndex) assert isinstance(self.datetime_index, gt.ABCDatetimeIndex) assert isinstance(self.timedelta_index, gt.ABCTimedeltaIndex) assert isinstance(self.period_index, gt.ABCPeriodIndex) assert isinstance(self.categorical_df.index, gt.ABCCategoricalIndex) assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndexClass) assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCIndexClass) assert isinstance(pd.Series([1, 2, 3]), gt.ABCSeries) assert isinstance(self.df, gt.ABCDataFrame) with catch_warnings(record=True): assert isinstance(self.df.to_panel(), gt.ABCPanel) assert isinstance(self.sparse_series, gt.ABCSparseSeries) assert isinstance(self.sparse_array, gt.ABCSparseArray) assert isinstance(self.sparse_frame, gt.ABCSparseDataFrame) assert isinstance(self.categorical, gt.ABCCategorical) assert isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCPeriod) assert isinstance(pd.DateOffset(), gt.ABCDateOffset) assert isinstance(pd.Period('2012', freq='A-DEC').freq, gt.ABCDateOffset) assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCDateOffset) assert isinstance(pd.Interval(0, 1.5), gt.ABCInterval) assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCInterval)
Example #18
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_ufunc_coercions(self): idx = self._holder([1, 2, 3, 4, 5], name='x') result = np.sqrt(idx) assert isinstance(result, Float64Index) exp = Float64Index(np.sqrt(np.array([1, 2, 3, 4, 5])), name='x') tm.assert_index_equal(result, exp) result = np.divide(idx, 2.) assert isinstance(result, Float64Index) exp = Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') tm.assert_index_equal(result, exp) # _evaluate_numeric_binop result = idx + 2. assert isinstance(result, Float64Index) exp = Float64Index([3., 4., 5., 6., 7.], name='x') tm.assert_index_equal(result, exp) result = idx - 2. assert isinstance(result, Float64Index) exp = Float64Index([-1., 0., 1., 2., 3.], name='x') tm.assert_index_equal(result, exp) result = idx * 1. assert isinstance(result, Float64Index) exp = Float64Index([1., 2., 3., 4., 5.], name='x') tm.assert_index_equal(result, exp) result = idx / 2. assert isinstance(result, Float64Index) exp = Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') tm.assert_index_equal(result, exp)
Example #19
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def create_index(self): return Float64Index(np.arange(5, dtype='float64'))
Example #20
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def setup_method(self, method): self.indices = dict(mixed=Float64Index([1.5, 2, 3, 4, 5]), float=Float64Index(np.arange(5) * 2.5), mixed_dec=Float64Index([5, 4, 3, 2, 1.5]), float_dec=Float64Index(np.arange(4, -1, -1) * 2.5)) self.setup_indices()
Example #21
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_get_loc(self): idx = Float64Index([0.0, 1.0, 2.0]) for method in [None, 'pad', 'backfill', 'nearest']: assert idx.get_loc(1, method) == 1 if method is not None: assert idx.get_loc(1, method, tolerance=0) == 1 for method, loc in [('pad', 1), ('backfill', 2), ('nearest', 1)]: assert idx.get_loc(1.1, method) == loc assert idx.get_loc(1.1, method, tolerance=0.9) == loc pytest.raises(KeyError, idx.get_loc, 'foo') pytest.raises(KeyError, idx.get_loc, 1.5) pytest.raises(KeyError, idx.get_loc, 1.5, method='pad', tolerance=0.1) with tm.assert_raises_regex(ValueError, 'must be numeric'): idx.get_loc(1.4, method='nearest', tolerance='foo') with pytest.raises(ValueError, match='must contain numeric elements'): idx.get_loc(1.4, method='nearest', tolerance=np.array(['foo'])) with pytest.raises( ValueError, match='tolerance size must match target index size'): idx.get_loc(1.4, method='nearest', tolerance=np.array([1, 2]))
Example #22
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_ufunc_compat(self): idx = self._holder(np.arange(5, dtype='int64')) result = np.sin(idx) expected = Float64Index(np.sin(np.arange(5, dtype='int64'))) tm.assert_index_equal(result, expected)
Example #23
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_rpow_float(self): # test power calculations both ways, GH 14973 idx = self.create_index() expected = pd.Float64Index(2.0**idx.values) result = 2.0**idx tm.assert_index_equal(result, expected)
Example #24
Source File: test_numeric.py From vnpy_crypto with MIT License | 5 votes |
def test_pow_float(self): # test power calculations both ways, GH 14973 idx = self.create_index() expected = pd.Float64Index(idx.values**2.0) result = idx**2.0 tm.assert_index_equal(result, expected)
Example #25
Source File: test_base.py From vnpy_crypto with MIT License | 5 votes |
def test_isin_nan_common_float64(self, nulls_fixture): if nulls_fixture is pd.NaT: pytest.skip("pd.NaT not compatible with Float64Index") # Float64Index overrides isin, so must be checked separately tm.assert_numpy_array_equal(Float64Index([1.0, nulls_fixture]).isin( [np.nan]), np.array([False, True])) # we cannot compare NaT with NaN tm.assert_numpy_array_equal(Float64Index([1.0, nulls_fixture]).isin( [pd.NaT]), np.array([False, False]))
Example #26
Source File: test_base.py From vnpy_crypto with MIT License | 5 votes |
def test_constructor_dtypes_to_float64(self, vals): index = Index(vals, dtype=float) assert isinstance(index, Float64Index)
Example #27
Source File: test_base.py From vnpy_crypto with MIT License | 5 votes |
def test_constructor_int_dtype_nan(self): # see gh-15187 data = [np.nan] expected = Float64Index(data) result = Index(data, dtype='float') tm.assert_index_equal(result, expected)
Example #28
Source File: test_arithmetic.py From vnpy_crypto with MIT License | 5 votes |
def test_tdi_div_tdlike_scalar_with_nat(self, delta): rng = TimedeltaIndex(['1 days', pd.NaT, '2 days'], name='foo') expected = Float64Index([12, np.nan, 24], name='foo') result = rng / delta tm.assert_index_equal(result, expected)
Example #29
Source File: test_generic.py From recruit with Apache License 2.0 | 5 votes |
def test_abc_types(self): assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndex) assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCInt64Index) assert isinstance(pd.UInt64Index([1, 2, 3]), gt.ABCUInt64Index) assert isinstance(pd.Float64Index([1, 2, 3]), gt.ABCFloat64Index) assert isinstance(self.multi_index, gt.ABCMultiIndex) assert isinstance(self.datetime_index, gt.ABCDatetimeIndex) assert isinstance(self.timedelta_index, gt.ABCTimedeltaIndex) assert isinstance(self.period_index, gt.ABCPeriodIndex) assert isinstance(self.categorical_df.index, gt.ABCCategoricalIndex) assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndexClass) assert isinstance(pd.Int64Index([1, 2, 3]), gt.ABCIndexClass) assert isinstance(pd.Series([1, 2, 3]), gt.ABCSeries) assert isinstance(self.df, gt.ABCDataFrame) with catch_warnings(record=True): simplefilter('ignore', FutureWarning) assert isinstance(self.df.to_panel(), gt.ABCPanel) assert isinstance(self.sparse_series, gt.ABCSparseSeries) assert isinstance(self.sparse_array, gt.ABCSparseArray) assert isinstance(self.sparse_frame, gt.ABCSparseDataFrame) assert isinstance(self.categorical, gt.ABCCategorical) assert isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCPeriod) assert isinstance(pd.DateOffset(), gt.ABCDateOffset) assert isinstance(pd.Period('2012', freq='A-DEC').freq, gt.ABCDateOffset) assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCDateOffset) assert isinstance(pd.Interval(0, 1.5), gt.ABCInterval) assert not isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCInterval) assert isinstance(self.datetime_array, gt.ABCDatetimeArray) assert not isinstance(self.datetime_index, gt.ABCDatetimeArray) assert isinstance(self.timedelta_array, gt.ABCTimedeltaArray) assert not isinstance(self.timedelta_index, gt.ABCTimedeltaArray)
Example #30
Source File: test_numeric.py From recruit with Apache License 2.0 | 5 votes |
def test_ufunc_coercions(self, holder): idx = holder([1, 2, 3, 4, 5], name='x') box = pd.Series if holder is pd.Series else pd.Index result = np.sqrt(idx) assert result.dtype == 'f8' and isinstance(result, box) exp = pd.Float64Index(np.sqrt(np.array([1, 2, 3, 4, 5])), name='x') exp = tm.box_expected(exp, box) tm.assert_equal(result, exp) result = np.divide(idx, 2.) assert result.dtype == 'f8' and isinstance(result, box) exp = pd.Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') exp = tm.box_expected(exp, box) tm.assert_equal(result, exp) # _evaluate_numeric_binop result = idx + 2. assert result.dtype == 'f8' and isinstance(result, box) exp = pd.Float64Index([3., 4., 5., 6., 7.], name='x') exp = tm.box_expected(exp, box) tm.assert_equal(result, exp) result = idx - 2. assert result.dtype == 'f8' and isinstance(result, box) exp = pd.Float64Index([-1., 0., 1., 2., 3.], name='x') exp = tm.box_expected(exp, box) tm.assert_equal(result, exp) result = idx * 1. assert result.dtype == 'f8' and isinstance(result, box) exp = pd.Float64Index([1., 2., 3., 4., 5.], name='x') exp = tm.box_expected(exp, box) tm.assert_equal(result, exp) result = idx / 2. assert result.dtype == 'f8' and isinstance(result, box) exp = pd.Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') exp = tm.box_expected(exp, box) tm.assert_equal(result, exp)