# Path: pysc2/lib/named_array.py
# class NamedDict(dict):
# class NamedNumpyArray(np.ndarray):
#   def __init__(self, *args, **kwargs):
#   def __new__(cls, values, names, *args, **kwargs):
#   def __array_finalize__(self, obj):
#   def __getattr__(self, name):
#   def __setattr__(self, name, value):
#   def __getitem__(self, indices):
#   def __setitem__(self, indices, value):
#   def __getslice__(self, i, j):  # deprecated, but still needed...
#   def __setslice__(self, i, j, seq):  # deprecated, but still needed...
#   def __repr__(self):
#   def __reduce__(self):
#   def __setstate__(self, state):
#   def _indices(self, indices):
#   def _get_index(self, dim, index):
# _NULL_SLICE = slice(None, None, None)


import collections
import pickle
import enum
import numpy as np
from absl.testing import absltest
from absl.testing import parameterized
from pysc2.lib import named_array
        [["a", "b"], ["c", "d"], ["e", "f"], ["g", "h"]])
    self.assertEqual(a.a.c.e.g, 0)
    self.assertEqual(a.b.c.f.g, 10)
    self.assertEqual(a.b.d.f.h, 15)
    self.assertArrayEqual(a[0, ..., 0], [[0, 2], [4, 6]])
    self.assertArrayEqual(a[0, ..., 1], [[1, 3], [5, 7]])
    self.assertArrayEqual(a[0, 0, ..., 1], [1, 3])
    self.assertArrayEqual(a[0, ..., 1, 1], [3, 7])
    self.assertArrayEqual(a[..., 1, 1], [[3, 7], [11, 15]])
    self.assertArrayEqual(a[1, 0, ...], [[8, 9], [10, 11]])

    self.assertArrayEqual(a["a", ..., "g"], [[0, 2], [4, 6]])
    self.assertArrayEqual(a["a", ...], [[[0, 1], [2, 3]], [[4, 5], [6, 7]]])
    self.assertArrayEqual(a[..., "g"], [[[0, 2], [4, 6]], [[8, 10], [12, 14]]])
    self.assertArrayEqual(a["a", "c"], [[0, 1], [2, 3]])
    self.assertArrayEqual(a["a", ...].c, [[0, 1], [2, 3]])
    self.assertArrayEqual(a["a", ..., "g"].c, [0, 2])

    with self.assertRaises(TypeError):
      a[np.array([[0, 1], [0, 1]])]  # pylint: disable=pointless-statement, expression-not-assigned

    with self.assertRaises(IndexError):
      a[..., 0, ...]  # pylint: disable=pointless-statement

  def test_string(self):
    a = named_array.NamedNumpyArray([1, 3, 6], ["a", "b", "c"], dtype=np.int32)
    self.assertEqual(str(a), "[1 3 6]")
    self.assertEqual(repr(a), ("NamedNumpyArray([1, 3, 6], ['a', 'b', 'c'], "
                               "dtype=int32)"))


# Path: pysc2/lib/named_array.py
# class NamedDict(dict):
# class NamedNumpyArray(np.ndarray):
#   def __init__(self, *args, **kwargs):
#   def __new__(cls, values, names, *args, **kwargs):
#   def __array_finalize__(self, obj):
#   def __getattr__(self, name):
#   def __setattr__(self, name, value):
#   def __getitem__(self, indices):
#   def __setitem__(self, indices, value):
#   def __getslice__(self, i, j):  # deprecated, but still needed...
#   def __setslice__(self, i, j, seq):  # deprecated, but still needed...
#   def __repr__(self):
#   def __reduce__(self):
#   def __setstate__(self, state):
#   def _indices(self, indices):
#   def _get_index(self, dim, index):
# _NULL_SLICE = slice(None, None, None)


# Path: pysc2/lib/named_array_test.py
import collections
import pickle
import enum
import numpy as np
from absl.testing import absltest
from absl.testing import parameterized
from pysc2.lib import named_array

        [["a", "b"], ["c", "d"], ["e", "f"], ["g", "h"]])
    self.assertEqual(a.a.c.e.g, 0)
    self.assertEqual(a.b.c.f.g, 10)
    self.assertEqual(a.b.d.f.h, 15)
    self.assertArrayEqual(a[0, ..., 0], [[0, 2], [4, 6]])
    self.assertArrayEqual(a[0, ..., 1], [[1, 3], [5, 7]])
    self.assertArrayEqual(a[0, 0, ..., 1], [1, 3])
    self.assertArrayEqual(a[0, ..., 1, 1], [3, 7])
    self.assertArrayEqual(a[..., 1, 1], [[3, 7], [11, 15]])
    self.assertArrayEqual(a[1, 0, ...], [[8, 9], [10, 11]])

    self.assertArrayEqual(a["a", ..., "g"], [[0, 2], [4, 6]])
    self.assertArrayEqual(a["a", ...], [[[0, 1], [2, 3]], [[4, 5], [6, 7]]])
    self.assertArrayEqual(a[..., "g"], [[[0, 2], [4, 6]], [[8, 10], [12, 14]]])
    self.assertArrayEqual(a["a", "c"], [[0, 1], [2, 3]])
    self.assertArrayEqual(a["a", ...].c, [[0, 1], [2, 3]])
    self.assertArrayEqual(a["a", ..., "g"].c, [0, 2])

    with self.assertRaises(TypeError):
      a[np.array([[0, 1], [0, 1]])]  # pylint: disable=pointless-statement, expression-not-assigned

    with self.assertRaises(IndexError):
      a[..., 0, ...]  # pylint: disable=pointless-statement

  def test_string(self):
    a = named_array.NamedNumpyArray([1, 3, 6], ["a", "b", "c"], dtype=np.int32)
    self.assertEqual(str(a), "[1 3 6]")
    self.assertEqual(repr(a), ("NamedNumpyArray([1, 3, 6], ['a', 'b', 'c'], "
                               "dtype=int32)"))


    a = named_array.NamedNumpyArray([[1, 3], [6, 8]], [None, ["a", "b"]])