It can only be used in a derogatory fashion, and I think the best way to demonstrate this is by comparing the definitions of "pedant" from a number of dictionaries:
A person who annoys other people by correcting small errors and giving
too much attention to minor details.
One who makes a show of knowledge;
One who is unimaginative or who unduly emphasizes minutiae in the
presentation or use of knowledge;
A formalist or precisionist in teaching.
A person who is too interested in formal rules and small details that are
A person who is excessively concerned with minor details and rules or
with displaying academic learning.
Someone who gives too much important to details and formal rules, especially
A person who relies too much on academic learning or who is concerned
chiefly with insignificant detail.
In each of these definitions, there is some mention of excess, arrogance, or annoyance. None of these are positive traits or qualities.
If I wanted to describe someone who always aimed to do the correct thing, pedant would not be my word of choice. I would probably choose one of (from Oxford Dictionaries):
Showing great attention to detail; very careful and precise:
"the designs are hand-glazed with meticulous care"
"he had always been so meticulous about his appearance"
Performed or written with great care and completeness:
"officers have made a thorough examination of the wreckage"
Taking pains to do something carefully and completely:
"the British authorities are very thorough"
Extremely thorough and careful:
"the rigorous testing of consumer products"
(Of a person) adhering strictly to a belief or system:
"a rigorous teetotaller"
Involving or relating to serious academic study:
"a scholarly career"
Having or showing knowledge, learning, or devotion of academic pursuits:
"a scholarly account of the period"
"an earnest, scholarly man"
My exact choice would depend on the message I was trying to put across, since the meanings are all slightly different.