test_floats.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. # -*- coding: utf-8 -*-
  2. from warnings import catch_warnings
  3. import numpy as np
  4. import pytest
  5. from pandas import (
  6. DataFrame, Float64Index, Index, Int64Index, RangeIndex, Series)
  7. import pandas.util.testing as tm
  8. from pandas.util.testing import assert_almost_equal, assert_series_equal
  9. ignore_ix = pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning")
  10. class TestFloatIndexers(object):
  11. def check(self, result, original, indexer, getitem):
  12. """
  13. comparator for results
  14. we need to take care if we are indexing on a
  15. Series or a frame
  16. """
  17. if isinstance(original, Series):
  18. expected = original.iloc[indexer]
  19. else:
  20. if getitem:
  21. expected = original.iloc[:, indexer]
  22. else:
  23. expected = original.iloc[indexer]
  24. assert_almost_equal(result, expected)
  25. def test_scalar_error(self):
  26. # GH 4892
  27. # float_indexers should raise exceptions
  28. # on appropriate Index types & accessors
  29. # this duplicates the code below
  30. # but is spefically testing for the error
  31. # message
  32. for index in [tm.makeStringIndex, tm.makeUnicodeIndex,
  33. tm.makeCategoricalIndex,
  34. tm.makeDateIndex, tm.makeTimedeltaIndex,
  35. tm.makePeriodIndex, tm.makeIntIndex,
  36. tm.makeRangeIndex]:
  37. i = index(5)
  38. s = Series(np.arange(len(i)), index=i)
  39. msg = 'Cannot index by location index'
  40. with pytest.raises(TypeError, match=msg):
  41. s.iloc[3.0]
  42. def f():
  43. s.iloc[3.0] = 0
  44. pytest.raises(TypeError, f)
  45. @ignore_ix
  46. def test_scalar_non_numeric(self):
  47. # GH 4892
  48. # float_indexers should raise exceptions
  49. # on appropriate Index types & accessors
  50. for index in [tm.makeStringIndex, tm.makeUnicodeIndex,
  51. tm.makeCategoricalIndex,
  52. tm.makeDateIndex, tm.makeTimedeltaIndex,
  53. tm.makePeriodIndex]:
  54. i = index(5)
  55. for s in [Series(
  56. np.arange(len(i)), index=i), DataFrame(
  57. np.random.randn(
  58. len(i), len(i)), index=i, columns=i)]:
  59. # getting
  60. for idxr, getitem in [(lambda x: x.ix, False),
  61. (lambda x: x.iloc, False),
  62. (lambda x: x, True)]:
  63. def f():
  64. with catch_warnings(record=True):
  65. idxr(s)[3.0]
  66. # gettitem on a DataFrame is a KeyError as it is indexing
  67. # via labels on the columns
  68. if getitem and isinstance(s, DataFrame):
  69. error = KeyError
  70. else:
  71. error = TypeError
  72. pytest.raises(error, f)
  73. # label based can be a TypeError or KeyError
  74. def f():
  75. s.loc[3.0]
  76. if s.index.inferred_type in ['string', 'unicode', 'mixed']:
  77. error = KeyError
  78. else:
  79. error = TypeError
  80. pytest.raises(error, f)
  81. # contains
  82. assert 3.0 not in s
  83. # setting with a float fails with iloc
  84. def f():
  85. s.iloc[3.0] = 0
  86. pytest.raises(TypeError, f)
  87. # setting with an indexer
  88. if s.index.inferred_type in ['categorical']:
  89. # Value or Type Error
  90. pass
  91. elif s.index.inferred_type in ['datetime64', 'timedelta64',
  92. 'period']:
  93. # these should prob work
  94. # and are inconsisten between series/dataframe ATM
  95. # for idxr in [lambda x: x.ix,
  96. # lambda x: x]:
  97. # s2 = s.copy()
  98. # def f():
  99. # idxr(s2)[3.0] = 0
  100. # pytest.raises(TypeError, f)
  101. pass
  102. else:
  103. s2 = s.copy()
  104. s2.loc[3.0] = 10
  105. assert s2.index.is_object()
  106. for idxr in [lambda x: x.ix,
  107. lambda x: x]:
  108. s2 = s.copy()
  109. with catch_warnings(record=True):
  110. idxr(s2)[3.0] = 0
  111. assert s2.index.is_object()
  112. # fallsback to position selection, series only
  113. s = Series(np.arange(len(i)), index=i)
  114. s[3]
  115. pytest.raises(TypeError, lambda: s[3.0])
  116. @ignore_ix
  117. def test_scalar_with_mixed(self):
  118. s2 = Series([1, 2, 3], index=['a', 'b', 'c'])
  119. s3 = Series([1, 2, 3], index=['a', 'b', 1.5])
  120. # lookup in a pure string index
  121. # with an invalid indexer
  122. for idxr in [lambda x: x.ix,
  123. lambda x: x,
  124. lambda x: x.iloc]:
  125. def f():
  126. with catch_warnings(record=True):
  127. idxr(s2)[1.0]
  128. pytest.raises(TypeError, f)
  129. pytest.raises(KeyError, lambda: s2.loc[1.0])
  130. result = s2.loc['b']
  131. expected = 2
  132. assert result == expected
  133. # mixed index so we have label
  134. # indexing
  135. for idxr in [lambda x: x]:
  136. def f():
  137. idxr(s3)[1.0]
  138. pytest.raises(TypeError, f)
  139. result = idxr(s3)[1]
  140. expected = 2
  141. assert result == expected
  142. # mixed index so we have label
  143. # indexing
  144. for idxr in [lambda x: x.ix]:
  145. with catch_warnings(record=True):
  146. def f():
  147. idxr(s3)[1.0]
  148. pytest.raises(TypeError, f)
  149. result = idxr(s3)[1]
  150. expected = 2
  151. assert result == expected
  152. pytest.raises(TypeError, lambda: s3.iloc[1.0])
  153. pytest.raises(KeyError, lambda: s3.loc[1.0])
  154. result = s3.loc[1.5]
  155. expected = 3
  156. assert result == expected
  157. @ignore_ix
  158. def test_scalar_integer(self):
  159. # test how scalar float indexers work on int indexes
  160. # integer index
  161. for i in [Int64Index(range(5)), RangeIndex(5)]:
  162. for s in [Series(np.arange(len(i))),
  163. DataFrame(np.random.randn(len(i), len(i)),
  164. index=i, columns=i)]:
  165. # coerce to equal int
  166. for idxr, getitem in [(lambda x: x.ix, False),
  167. (lambda x: x.loc, False),
  168. (lambda x: x, True)]:
  169. with catch_warnings(record=True):
  170. result = idxr(s)[3.0]
  171. self.check(result, s, 3, getitem)
  172. # coerce to equal int
  173. for idxr, getitem in [(lambda x: x.ix, False),
  174. (lambda x: x.loc, False),
  175. (lambda x: x, True)]:
  176. if isinstance(s, Series):
  177. def compare(x, y):
  178. assert x == y
  179. expected = 100
  180. else:
  181. compare = tm.assert_series_equal
  182. if getitem:
  183. expected = Series(100,
  184. index=range(len(s)), name=3)
  185. else:
  186. expected = Series(100.,
  187. index=range(len(s)), name=3)
  188. s2 = s.copy()
  189. with catch_warnings(record=True):
  190. idxr(s2)[3.0] = 100
  191. result = idxr(s2)[3.0]
  192. compare(result, expected)
  193. result = idxr(s2)[3]
  194. compare(result, expected)
  195. # contains
  196. # coerce to equal int
  197. assert 3.0 in s
  198. @ignore_ix
  199. def test_scalar_float(self):
  200. # scalar float indexers work on a float index
  201. index = Index(np.arange(5.))
  202. for s in [Series(np.arange(len(index)), index=index),
  203. DataFrame(np.random.randn(len(index), len(index)),
  204. index=index, columns=index)]:
  205. # assert all operations except for iloc are ok
  206. indexer = index[3]
  207. for idxr, getitem in [(lambda x: x.ix, False),
  208. (lambda x: x.loc, False),
  209. (lambda x: x, True)]:
  210. # getting
  211. result = idxr(s)[indexer]
  212. self.check(result, s, 3, getitem)
  213. # setting
  214. s2 = s.copy()
  215. def f():
  216. with catch_warnings(record=True):
  217. idxr(s2)[indexer] = expected
  218. with catch_warnings(record=True):
  219. result = idxr(s2)[indexer]
  220. self.check(result, s, 3, getitem)
  221. # random integer is a KeyError
  222. with catch_warnings(record=True):
  223. pytest.raises(KeyError, lambda: idxr(s)[3.5])
  224. # contains
  225. assert 3.0 in s
  226. # iloc succeeds with an integer
  227. expected = s.iloc[3]
  228. s2 = s.copy()
  229. s2.iloc[3] = expected
  230. result = s2.iloc[3]
  231. self.check(result, s, 3, False)
  232. # iloc raises with a float
  233. pytest.raises(TypeError, lambda: s.iloc[3.0])
  234. def g():
  235. s2.iloc[3.0] = 0
  236. pytest.raises(TypeError, g)
  237. @ignore_ix
  238. def test_slice_non_numeric(self):
  239. # GH 4892
  240. # float_indexers should raise exceptions
  241. # on appropriate Index types & accessors
  242. for index in [tm.makeStringIndex, tm.makeUnicodeIndex,
  243. tm.makeDateIndex, tm.makeTimedeltaIndex,
  244. tm.makePeriodIndex]:
  245. index = index(5)
  246. for s in [Series(range(5), index=index),
  247. DataFrame(np.random.randn(5, 2), index=index)]:
  248. # getitem
  249. for l in [slice(3.0, 4),
  250. slice(3, 4.0),
  251. slice(3.0, 4.0)]:
  252. def f():
  253. s.iloc[l]
  254. pytest.raises(TypeError, f)
  255. for idxr in [lambda x: x.ix,
  256. lambda x: x.loc,
  257. lambda x: x.iloc,
  258. lambda x: x]:
  259. def f():
  260. with catch_warnings(record=True):
  261. idxr(s)[l]
  262. pytest.raises(TypeError, f)
  263. # setitem
  264. for l in [slice(3.0, 4),
  265. slice(3, 4.0),
  266. slice(3.0, 4.0)]:
  267. def f():
  268. s.iloc[l] = 0
  269. pytest.raises(TypeError, f)
  270. for idxr in [lambda x: x.ix,
  271. lambda x: x.loc,
  272. lambda x: x.iloc,
  273. lambda x: x]:
  274. def f():
  275. with catch_warnings(record=True):
  276. idxr(s)[l] = 0
  277. pytest.raises(TypeError, f)
  278. @ignore_ix
  279. def test_slice_integer(self):
  280. # same as above, but for Integer based indexes
  281. # these coerce to a like integer
  282. # oob indicates if we are out of bounds
  283. # of positional indexing
  284. for index, oob in [(Int64Index(range(5)), False),
  285. (RangeIndex(5), False),
  286. (Int64Index(range(5)) + 10, True)]:
  287. # s is an in-range index
  288. s = Series(range(5), index=index)
  289. # getitem
  290. for l in [slice(3.0, 4),
  291. slice(3, 4.0),
  292. slice(3.0, 4.0)]:
  293. for idxr in [lambda x: x.loc,
  294. lambda x: x.ix]:
  295. with catch_warnings(record=True):
  296. result = idxr(s)[l]
  297. # these are all label indexing
  298. # except getitem which is positional
  299. # empty
  300. if oob:
  301. indexer = slice(0, 0)
  302. else:
  303. indexer = slice(3, 5)
  304. self.check(result, s, indexer, False)
  305. # positional indexing
  306. def f():
  307. s[l]
  308. pytest.raises(TypeError, f)
  309. # getitem out-of-bounds
  310. for l in [slice(-6, 6),
  311. slice(-6.0, 6.0)]:
  312. for idxr in [lambda x: x.loc,
  313. lambda x: x.ix]:
  314. with catch_warnings(record=True):
  315. result = idxr(s)[l]
  316. # these are all label indexing
  317. # except getitem which is positional
  318. # empty
  319. if oob:
  320. indexer = slice(0, 0)
  321. else:
  322. indexer = slice(-6, 6)
  323. self.check(result, s, indexer, False)
  324. # positional indexing
  325. def f():
  326. s[slice(-6.0, 6.0)]
  327. pytest.raises(TypeError, f)
  328. # getitem odd floats
  329. for l, res1 in [(slice(2.5, 4), slice(3, 5)),
  330. (slice(2, 3.5), slice(2, 4)),
  331. (slice(2.5, 3.5), slice(3, 4))]:
  332. for idxr in [lambda x: x.loc,
  333. lambda x: x.ix]:
  334. with catch_warnings(record=True):
  335. result = idxr(s)[l]
  336. if oob:
  337. res = slice(0, 0)
  338. else:
  339. res = res1
  340. self.check(result, s, res, False)
  341. # positional indexing
  342. def f():
  343. s[l]
  344. pytest.raises(TypeError, f)
  345. # setitem
  346. for l in [slice(3.0, 4),
  347. slice(3, 4.0),
  348. slice(3.0, 4.0)]:
  349. for idxr in [lambda x: x.loc,
  350. lambda x: x.ix]:
  351. sc = s.copy()
  352. with catch_warnings(record=True):
  353. idxr(sc)[l] = 0
  354. result = idxr(sc)[l].values.ravel()
  355. assert (result == 0).all()
  356. # positional indexing
  357. def f():
  358. s[l] = 0
  359. pytest.raises(TypeError, f)
  360. def test_integer_positional_indexing(self):
  361. """ make sure that we are raising on positional indexing
  362. w.r.t. an integer index """
  363. s = Series(range(2, 6), index=range(2, 6))
  364. result = s[2:4]
  365. expected = s.iloc[2:4]
  366. assert_series_equal(result, expected)
  367. for idxr in [lambda x: x,
  368. lambda x: x.iloc]:
  369. for l in [slice(2, 4.0),
  370. slice(2.0, 4),
  371. slice(2.0, 4.0)]:
  372. def f():
  373. idxr(s)[l]
  374. pytest.raises(TypeError, f)
  375. @ignore_ix
  376. def test_slice_integer_frame_getitem(self):
  377. # similar to above, but on the getitem dim (of a DataFrame)
  378. for index in [Int64Index(range(5)), RangeIndex(5)]:
  379. s = DataFrame(np.random.randn(5, 2), index=index)
  380. def f(idxr):
  381. # getitem
  382. for l in [slice(0.0, 1),
  383. slice(0, 1.0),
  384. slice(0.0, 1.0)]:
  385. result = idxr(s)[l]
  386. indexer = slice(0, 2)
  387. self.check(result, s, indexer, False)
  388. # positional indexing
  389. def f():
  390. s[l]
  391. pytest.raises(TypeError, f)
  392. # getitem out-of-bounds
  393. for l in [slice(-10, 10),
  394. slice(-10.0, 10.0)]:
  395. result = idxr(s)[l]
  396. self.check(result, s, slice(-10, 10), True)
  397. # positional indexing
  398. def f():
  399. s[slice(-10.0, 10.0)]
  400. pytest.raises(TypeError, f)
  401. # getitem odd floats
  402. for l, res in [(slice(0.5, 1), slice(1, 2)),
  403. (slice(0, 0.5), slice(0, 1)),
  404. (slice(0.5, 1.5), slice(1, 2))]:
  405. result = idxr(s)[l]
  406. self.check(result, s, res, False)
  407. # positional indexing
  408. def f():
  409. s[l]
  410. pytest.raises(TypeError, f)
  411. # setitem
  412. for l in [slice(3.0, 4),
  413. slice(3, 4.0),
  414. slice(3.0, 4.0)]:
  415. sc = s.copy()
  416. idxr(sc)[l] = 0
  417. result = idxr(sc)[l].values.ravel()
  418. assert (result == 0).all()
  419. # positional indexing
  420. def f():
  421. s[l] = 0
  422. pytest.raises(TypeError, f)
  423. f(lambda x: x.loc)
  424. with catch_warnings(record=True):
  425. f(lambda x: x.ix)
  426. @ignore_ix
  427. def test_slice_float(self):
  428. # same as above, but for floats
  429. index = Index(np.arange(5.)) + 0.1
  430. for s in [Series(range(5), index=index),
  431. DataFrame(np.random.randn(5, 2), index=index)]:
  432. for l in [slice(3.0, 4),
  433. slice(3, 4.0),
  434. slice(3.0, 4.0)]:
  435. expected = s.iloc[3:4]
  436. for idxr in [lambda x: x.ix,
  437. lambda x: x.loc,
  438. lambda x: x]:
  439. # getitem
  440. with catch_warnings(record=True):
  441. result = idxr(s)[l]
  442. if isinstance(s, Series):
  443. tm.assert_series_equal(result, expected)
  444. else:
  445. tm.assert_frame_equal(result, expected)
  446. # setitem
  447. s2 = s.copy()
  448. with catch_warnings(record=True):
  449. idxr(s2)[l] = 0
  450. result = idxr(s2)[l].values.ravel()
  451. assert (result == 0).all()
  452. def test_floating_index_doc_example(self):
  453. index = Index([1.5, 2, 3, 4.5, 5])
  454. s = Series(range(5), index=index)
  455. assert s[3] == 2
  456. assert s.loc[3] == 2
  457. assert s.loc[3] == 2
  458. assert s.iloc[3] == 3
  459. def test_floating_misc(self):
  460. # related 236
  461. # scalar/slicing of a float index
  462. s = Series(np.arange(5), index=np.arange(5) * 2.5, dtype=np.int64)
  463. # label based slicing
  464. result1 = s[1.0:3.0]
  465. result2 = s.loc[1.0:3.0]
  466. result3 = s.loc[1.0:3.0]
  467. assert_series_equal(result1, result2)
  468. assert_series_equal(result1, result3)
  469. # exact indexing when found
  470. result1 = s[5.0]
  471. result2 = s.loc[5.0]
  472. result3 = s.loc[5.0]
  473. assert result1 == result2
  474. assert result1 == result3
  475. result1 = s[5]
  476. result2 = s.loc[5]
  477. result3 = s.loc[5]
  478. assert result1 == result2
  479. assert result1 == result3
  480. assert s[5.0] == s[5]
  481. # value not found (and no fallbacking at all)
  482. # scalar integers
  483. pytest.raises(KeyError, lambda: s.loc[4])
  484. pytest.raises(KeyError, lambda: s.loc[4])
  485. pytest.raises(KeyError, lambda: s[4])
  486. # fancy floats/integers create the correct entry (as nan)
  487. # fancy tests
  488. expected = Series([2, 0], index=Float64Index([5.0, 0.0]))
  489. for fancy_idx in [[5.0, 0.0], np.array([5.0, 0.0])]: # float
  490. assert_series_equal(s[fancy_idx], expected)
  491. assert_series_equal(s.loc[fancy_idx], expected)
  492. assert_series_equal(s.loc[fancy_idx], expected)
  493. expected = Series([2, 0], index=Index([5, 0], dtype='int64'))
  494. for fancy_idx in [[5, 0], np.array([5, 0])]: # int
  495. assert_series_equal(s[fancy_idx], expected)
  496. assert_series_equal(s.loc[fancy_idx], expected)
  497. assert_series_equal(s.loc[fancy_idx], expected)
  498. # all should return the same as we are slicing 'the same'
  499. result1 = s.loc[2:5]
  500. result2 = s.loc[2.0:5.0]
  501. result3 = s.loc[2.0:5]
  502. result4 = s.loc[2.1:5]
  503. assert_series_equal(result1, result2)
  504. assert_series_equal(result1, result3)
  505. assert_series_equal(result1, result4)
  506. # previously this did fallback indexing
  507. result1 = s[2:5]
  508. result2 = s[2.0:5.0]
  509. result3 = s[2.0:5]
  510. result4 = s[2.1:5]
  511. assert_series_equal(result1, result2)
  512. assert_series_equal(result1, result3)
  513. assert_series_equal(result1, result4)
  514. result1 = s.loc[2:5]
  515. result2 = s.loc[2.0:5.0]
  516. result3 = s.loc[2.0:5]
  517. result4 = s.loc[2.1:5]
  518. assert_series_equal(result1, result2)
  519. assert_series_equal(result1, result3)
  520. assert_series_equal(result1, result4)
  521. # combined test
  522. result1 = s.loc[2:5]
  523. result2 = s.loc[2:5]
  524. result3 = s[2:5]
  525. assert_series_equal(result1, result2)
  526. assert_series_equal(result1, result3)
  527. # list selection
  528. result1 = s[[0.0, 5, 10]]
  529. result2 = s.loc[[0.0, 5, 10]]
  530. result3 = s.loc[[0.0, 5, 10]]
  531. result4 = s.iloc[[0, 2, 4]]
  532. assert_series_equal(result1, result2)
  533. assert_series_equal(result1, result3)
  534. assert_series_equal(result1, result4)
  535. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
  536. result1 = s[[1.6, 5, 10]]
  537. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
  538. result2 = s.loc[[1.6, 5, 10]]
  539. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
  540. result3 = s.loc[[1.6, 5, 10]]
  541. assert_series_equal(result1, result2)
  542. assert_series_equal(result1, result3)
  543. assert_series_equal(result1, Series(
  544. [np.nan, 2, 4], index=[1.6, 5, 10]))
  545. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
  546. result1 = s[[0, 1, 2]]
  547. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
  548. result2 = s.loc[[0, 1, 2]]
  549. with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
  550. result3 = s.loc[[0, 1, 2]]
  551. assert_series_equal(result1, result2)
  552. assert_series_equal(result1, result3)
  553. assert_series_equal(result1, Series(
  554. [0.0, np.nan, np.nan], index=[0, 1, 2]))
  555. result1 = s.loc[[2.5, 5]]
  556. result2 = s.loc[[2.5, 5]]
  557. assert_series_equal(result1, result2)
  558. assert_series_equal(result1, Series([1, 2], index=[2.5, 5.0]))
  559. result1 = s[[2.5]]
  560. result2 = s.loc[[2.5]]
  561. result3 = s.loc[[2.5]]
  562. assert_series_equal(result1, result2)
  563. assert_series_equal(result1, result3)
  564. assert_series_equal(result1, Series([1], index=[2.5]))
  565. def test_floating_tuples(self):
  566. # see gh-13509
  567. s = Series([(1, 1), (2, 2), (3, 3)], index=[0.0, 0.1, 0.2], name='foo')
  568. result = s[0.0]
  569. assert result == (1, 1)
  570. expected = Series([(1, 1), (2, 2)], index=[0.0, 0.0], name='foo')
  571. s = Series([(1, 1), (2, 2), (3, 3)], index=[0.0, 0.0, 0.2], name='foo')
  572. result = s[0.0]
  573. tm.assert_series_equal(result, expected)
  574. def test_float64index_slicing_bug(self):
  575. # GH 5557, related to slicing a float index
  576. ser = {256: 2321.0,
  577. 1: 78.0,
  578. 2: 2716.0,
  579. 3: 0.0,
  580. 4: 369.0,
  581. 5: 0.0,
  582. 6: 269.0,
  583. 7: 0.0,
  584. 8: 0.0,
  585. 9: 0.0,
  586. 10: 3536.0,
  587. 11: 0.0,
  588. 12: 24.0,
  589. 13: 0.0,
  590. 14: 931.0,
  591. 15: 0.0,
  592. 16: 101.0,
  593. 17: 78.0,
  594. 18: 9643.0,
  595. 19: 0.0,
  596. 20: 0.0,
  597. 21: 0.0,
  598. 22: 63761.0,
  599. 23: 0.0,
  600. 24: 446.0,
  601. 25: 0.0,
  602. 26: 34773.0,
  603. 27: 0.0,
  604. 28: 729.0,
  605. 29: 78.0,
  606. 30: 0.0,
  607. 31: 0.0,
  608. 32: 3374.0,
  609. 33: 0.0,
  610. 34: 1391.0,
  611. 35: 0.0,
  612. 36: 361.0,
  613. 37: 0.0,
  614. 38: 61808.0,
  615. 39: 0.0,
  616. 40: 0.0,
  617. 41: 0.0,
  618. 42: 6677.0,
  619. 43: 0.0,
  620. 44: 802.0,
  621. 45: 0.0,
  622. 46: 2691.0,
  623. 47: 0.0,
  624. 48: 3582.0,
  625. 49: 0.0,
  626. 50: 734.0,
  627. 51: 0.0,
  628. 52: 627.0,
  629. 53: 70.0,
  630. 54: 2584.0,
  631. 55: 0.0,
  632. 56: 324.0,
  633. 57: 0.0,
  634. 58: 605.0,
  635. 59: 0.0,
  636. 60: 0.0,
  637. 61: 0.0,
  638. 62: 3989.0,
  639. 63: 10.0,
  640. 64: 42.0,
  641. 65: 0.0,
  642. 66: 904.0,
  643. 67: 0.0,
  644. 68: 88.0,
  645. 69: 70.0,
  646. 70: 8172.0,
  647. 71: 0.0,
  648. 72: 0.0,
  649. 73: 0.0,
  650. 74: 64902.0,
  651. 75: 0.0,
  652. 76: 347.0,
  653. 77: 0.0,
  654. 78: 36605.0,
  655. 79: 0.0,
  656. 80: 379.0,
  657. 81: 70.0,
  658. 82: 0.0,
  659. 83: 0.0,
  660. 84: 3001.0,
  661. 85: 0.0,
  662. 86: 1630.0,
  663. 87: 7.0,
  664. 88: 364.0,
  665. 89: 0.0,
  666. 90: 67404.0,
  667. 91: 9.0,
  668. 92: 0.0,
  669. 93: 0.0,
  670. 94: 7685.0,
  671. 95: 0.0,
  672. 96: 1017.0,
  673. 97: 0.0,
  674. 98: 2831.0,
  675. 99: 0.0,
  676. 100: 2963.0,
  677. 101: 0.0,
  678. 102: 854.0,
  679. 103: 0.0,
  680. 104: 0.0,
  681. 105: 0.0,
  682. 106: 0.0,
  683. 107: 0.0,
  684. 108: 0.0,
  685. 109: 0.0,
  686. 110: 0.0,
  687. 111: 0.0,
  688. 112: 0.0,
  689. 113: 0.0,
  690. 114: 0.0,
  691. 115: 0.0,
  692. 116: 0.0,
  693. 117: 0.0,
  694. 118: 0.0,
  695. 119: 0.0,
  696. 120: 0.0,
  697. 121: 0.0,
  698. 122: 0.0,
  699. 123: 0.0,
  700. 124: 0.0,
  701. 125: 0.0,
  702. 126: 67744.0,
  703. 127: 22.0,
  704. 128: 264.0,
  705. 129: 0.0,
  706. 260: 197.0,
  707. 268: 0.0,
  708. 265: 0.0,
  709. 269: 0.0,
  710. 261: 0.0,
  711. 266: 1198.0,
  712. 267: 0.0,
  713. 262: 2629.0,
  714. 258: 775.0,
  715. 257: 0.0,
  716. 263: 0.0,
  717. 259: 0.0,
  718. 264: 163.0,
  719. 250: 10326.0,
  720. 251: 0.0,
  721. 252: 1228.0,
  722. 253: 0.0,
  723. 254: 2769.0,
  724. 255: 0.0}
  725. # smoke test for the repr
  726. s = Series(ser)
  727. result = s.value_counts()
  728. str(result)