Skip to content

Commit

Permalink
Seeing if this fixes the pytest errors, (I'll try to find a nicer way…
Browse files Browse the repository at this point in the history
… to do it in a future commit)
  • Loading branch information
bryan-harter committed Oct 12, 2023
1 parent 5c61111 commit 44f5ac7
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions cdflib/cdfwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2330,30 +2330,48 @@ def _convert_data(self, data_type: int, num_elems: int, num_values: int, indata:
elif isinstance(indata, str):
return 1, indata.ljust(num_elems, "\x00").encode()
else:
tofrom = self._convert_option()
dt_string = self._convert_type(data_type)
if data_type == self.CDF_EPOCH16:
num_elems = 2 * num_elems
try:
recs = int(len(indata) / recSize)
except Exception:
recs = 1
if data_type == self.CDF_EPOCH16:
complex_data = []
if recs > 1:
for x in range(0, recs):
acomplex = indata[x]
complex_data.append(acomplex.real)
complex_data.append(acomplex.imag)
indata_numpy = np.array(indata)
tofrom = self._convert_option()
npdata = self._convert_nptype(data_type, indata_numpy)
if indata_numpy.size == 0: # Check if the data being read in is zero size
recs = 0
elif indata_numpy.size == num_values * num_elems: # Check if only one record is being read in
recs = 1
else:
complex_data.append(indata.real)
complex_data.append(indata.imag)
indata = complex_data
form = tofrom + str(recs * num_values * num_elems) + dt_string
if recs * num_values * num_elems > 1:
return recs, struct.pack(form, *indata)
else:
return recs, struct.pack(form, indata)
recs = len(indata_numpy)
dt_string = self._convert_type(data_type)
if data_type == self.CDF_EPOCH16:
num_elems = 2 * num_elems
form = str(recs * num_values * num_elems) + dt_string
form2 = tofrom + str(recs * num_values * num_elems) + dt_string
datau = struct.unpack(form, npdata)
return recs, struct.pack(form2, *datau)
except:
tofrom = self._convert_option()
dt_string = self._convert_type(data_type)
if data_type == self.CDF_EPOCH16:
num_elems = 2 * num_elems
try:
recs = int(len(indata) / recSize)
except Exception:
recs = 1
if data_type == self.CDF_EPOCH16:
complex_data = []
if recs > 1:
for x in range(0, recs):
acomplex = indata[x]
complex_data.append(acomplex.real)
complex_data.append(acomplex.imag)
else:
complex_data.append(indata.real)
complex_data.append(indata.imag)
indata = complex_data
form = tofrom + str(recs * num_values * num_elems) + dt_string
if recs * num_values * num_elems > 1:
return recs, struct.pack(form, *indata)
else:
return recs, struct.pack(form, indata)

def _num_values(self, zVar: bool, varNum: int) -> int:
"""
Expand Down

0 comments on commit 44f5ac7

Please sign in to comment.