0

As you can see from the following ipdb log, extra zero dates are added to pre and post arrays. How can i fix this? And why this happens?

ipdb> pre
(datetime.datetime(2013, 12, 31, 9, 58), 0, 1)

ipdb> post
(datetime.datetime(2013, 12, 31, 13, 15), 0, 1)

ipdb> RDT
RDT = [(COL_TIME, 'M8[s]'), (COL_STATUS, 'b'), (COL_MOBILE, 'b')]

ipdb> RMATCH
RMATCH = [(COL_PRE, RDT), (COL_POST, RDT)]

ipdb> ppre, ppost = np.array(pre, dtype=RDT), np.array(post, dtype=RDT)

ipdb> ppre
array((datetime.datetime(2013, 12, 31, 9, 58), 0, 1), 
      dtype=[('TIME', '<M8[s]'), ('STATUS', 'i1'), ('MOBILE', 'i1')])

ipdb> np.array([ppre, ppost], dtype=RMATCH)
array([ ((datetime.datetime(2013, 12, 31, 9, 58), 0, 1), (datetime.datetime(1970, 1, 1, 0, 0), 0, 0)),
       ((datetime.datetime(2013, 12, 31, 13, 15), 0, 1), (datetime.datetime(1970, 1, 1, 0, 0), 0, 0))], 
      dtype=[('PRE', [('TIME', '<M8[s]'), ('STATUS', 'i1'), ('MOBILE', 'i1')]), ('POST', [('TIME', '<M8[s]'), ('STATUS', 'i1'), ('MOBILE', 'i1')])])

1 Answer 1

1

Your last result is an array with dtype RMATCH containing two elements. ppre and ppost were each converted to this dtype.

If you expected an array with a single element, with ppre filling the first field of the RMATCH dtype and ppost filling the second, try this:

np.array([(ppre, ppost)], dtype=RMATCH)

(Note the extra parentheses.)

I'm not sure if it is a bug, a wart or a feature that np.array([ppre, ppost], dtype=RMATCH) didn't raise an error, and instead filled in the unused fields with 0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.