def _compareRoundTrip(self, data): """ Make sure that data is unchanged by packing/unpacking. """ packed, attrs = database3.packSpecialData(data, "testing") roundTrip = database3.unpackSpecialData(packed, attrs, "testing") self._compareArrays(data, roundTrip)
def test_replaceNones(self): """ This definitely needs some work. """ data3 = numpy.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) data1 = numpy.array([1, 2, 3, 4, 5, 6, 7, 8]) data1iNones = numpy.array([1, 2, None, 5, 6]) data1fNones = numpy.array([None, 2.0, None, 5.0, 6.0]) data2fNones = numpy.array([None, [[1.0, 2.0, 6.0], [2.0, 3.0, 4.0]]]) data_jag = numpy.array([[[1, 2], [3, 4]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]]]) data_dict = numpy.array([{ "bar": 2, "baz": 3 }, { "foo": 4, "baz": 6 }, { "foo": 7, "bar": 8 }]) # nones = numpy.where([d is None for d in data1])[0] # conv_d1 = database.replaceNonesWithNonsense(data1, None, nones) print("data3: ", database.packSpecialData(data3, "")) print("data_jag", database.packSpecialData(data_jag, "")) # print("data1", database.packSpecialData(data1, "")) print("data1iNones", database.packSpecialData(data1iNones, "")) print("data1fNones", database.packSpecialData(data1fNones, "")) print("data2fNones", database.packSpecialData(data2fNones, "")) print("dataDict", database.packSpecialData(data_dict, "")) packedData, attrs = database.packSpecialData(data_jag, "") roundTrip = database.unpackSpecialData(packedData, attrs, "") print("round-tripped jagged:", roundTrip) print("round-tripped dtype:", roundTrip.dtype) packedData, attrs = database.packSpecialData(data_dict, "") roundTrip = database.unpackSpecialData(packedData, attrs, "") print("round-tripped dict:", roundTrip)