def test_to_globals(self): with pytest.warns(RuntimeWarning) as caught_warnings: self.session.to_globals() assert len(caught_warnings) == 1 assert caught_warnings[0].message.args[0] == "Session.to_globals should usually only be used in interactive " \ "consoles and not in scripts. Use warn=False to deactivate this " \ "warning." assert caught_warnings[0].filename == __file__ self.assertIs(a, self.a) self.assertIs(b, self.b) self.assertIs(c, self.c) self.assertIs(d, self.d) self.assertIs(e, self.e) self.assertIs(f, self.f) self.assertIs(g, self.g) # test inplace backup_dest = e backup_value = self.session.e.copy() self.session.e = zeros_like(e) self.session.to_globals(inplace=True, warn=False) # check the variable is correct (the same as before) self.assertIs(e, backup_dest) self.assertIsNot(e, self.session.e) # check the content has changed assert_array_nan_equal(e, self.session.e) self.assertFalse(larray_equal(e, backup_value))
def equal(o1, o2): if isinstance(o1, LArray) or isinstance(o2, LArray): return larray_equal(o1, o2) elif isinstance(o1, Axis) or isinstance(o2, Axis): return o1.equals(o2) else: return o1 == o2
def test_array_method(self): with open_excel(visible=False) as wb: sheet = wb[0] # normal test array arr1 = ndtest((2, 3)) sheet['A1'] = arr1.dump() res1 = sheet.array('B2:D3', 'A2:A3', 'B1:D1', names=['a', 'b']) assert larray_equal(res1, arr1) # array with int labels arr2 = ndrange('0..1;0..2') sheet['A1'] = arr2.dump() res2 = sheet.array('B2:D3', 'A2:A3', 'B1:D1') # larray_equal passes even if the labels are floats... assert larray_equal(res2, arr2) # so we check the dtype explicitly assert res2.axes[0].labels.dtype == arr2.axes[0].labels.dtype assert res2.axes[1].labels.dtype == arr2.axes[1].labels.dtype
def test_aslarray(self): with open_excel(visible=False) as wb: sheet = wb[0] arr1 = ndrange((2, 3)) # no header so that we have an uniform dtype for the whole sheet sheet['A1'] = arr1 res1 = aslarray(sheet['A1:C2']) assert larray_equal(res1, arr1) assert res1.dtype == arr1.dtype
def test_get_and_set_item(self): arr = ndtest((2, 3)) with open_excel(visible=False) as wb: sheet = wb[0] # set a few values sheet['A1'] = 1.5 sheet['A2'] = 2 sheet['A3'] = True sheet['A4'] = 'toto' # array without header sheet['A5'] = arr # array with header sheet['A8'] = arr.dump() # read them back assert sheet['A1'].value == 1.5 assert sheet['A2'].value == 2 assert sheet['A3'].value == True assert sheet['A4'].value == 'toto' # array without header assert np.array_equal(sheet['A5:C6'].value, arr.data) # array with header assert larray_equal(sheet['A8:D10'].load(), arr)