Exemplo n.º 1
0
 def test_get_hashable_series(self) -> None:
     s = pd.Series(dict(a=8, b=dict(c=9, d="foo")), name="bar")
     s_hashable = get_hashable(s)
     s_sub_expected = frozenset((("c", 9), ("d", "foo")))
     s_expected = frozenset((("a", 8), ("b", s_sub_expected)))
     self.assertEqual(s_hashable, s_expected)
     self.assertEqual(hash(s_hashable), hash(s_expected))
Exemplo n.º 2
0
 def test_get_hashable_dict(self) -> None:
     d = dict(a=8, b=dict(c=9, d="foo"))
     d_hashable = get_hashable(d)
     d_sub_expected = frozenset((("c", 9), ("d", "foo")))
     d_expected = frozenset((("a", 8), ("b", d_sub_expected)))
     self.assertEqual(d_hashable, d_expected)
     self.assertEqual(hash(d_hashable), hash(d_expected))
Exemplo n.º 3
0
 def test_get_hashable_series_with_doc(self) -> None:
     nlp = spacy.load("en_core_web_sm")
     doc = nlp("Foo went to the bar.")
     s = pd.Series(dict(a=8, b=doc), name="baz")
     s_hashable = get_hashable(s)
     s_expected = frozenset((("a", 8), ("b", doc)))
     self.assertEqual(s_hashable, s_expected)
     self.assertEqual(hash(s_hashable), hash(s_expected))
Exemplo n.º 4
0
 def test_get_hashable_unhashable(self) -> None:
     v = pd.DataFrame(dict(a=[4, 5], b=[1, 2]))
     x = (8, dict(a=v))
     with self.assertRaises(ValueError):
         get_hashable(x)
Exemplo n.º 5
0
 def test_get_hashable_ndarray(self) -> None:
     v = np.array([[3, 6, 9], [0.4, 0.8, 0.12]])
     x = (8, dict(a=v))
     x_hashable = get_hashable(x)
     x_expected = (8, frozenset((("a", v.data.tobytes()),)))
     self.assertEqual(x_hashable, x_expected)
Exemplo n.º 6
0
 def test_get_hashable_list(self) -> None:
     c = [8, dict(c=9, d="foo")]
     c_hashable = get_hashable(c)
     c_expected = (8, frozenset((("c", 9), ("d", "foo"))))
     self.assertEqual(c_hashable, c_expected)
     self.assertEqual(hash(c_hashable), hash(c_expected))
Exemplo n.º 7
0
 def test_get_hashable_hashable(self) -> None:
     x = (8, "abc")
     x_hashable = get_hashable(x)
     self.assertEqual(x, x_hashable)