Weird Pydantic Errors

If your Pydantic object validation errors look like this, the reason is simple:

2 validation errors for DetailedDemand
ordqty
  __init__() takes exactly 3 positional arguments (2 given) (type=type_error)
Z
  __init__() takes exactly 3 positional arguments (2 given) (type=type_error)

You’ve raised ValidationErrors in the validator, rather than ValueErrors, TypeErrors or similar. Don’t raise ValidationErrors there, those are for collecting other errors.

Validating a DataFrame against a Pydantic model

This works:

valid_instances = []
validation_exceptions = [] 
for row in df_in.itertuples(index=False):
    try:
        valid_instances.append(
            validity_class(
                **{
                    key: row[i]
                    for i, key in enumerate(validity_class.__
                }
            )
        )
    except ValidationError as ve:  # pylint: disable=invalid-name
        validation_exceptions.append(ve)
 

The main issue seems to be getting good validation error messages.

Basic Python Logging

This works quite well, after importing the sys and logging packages. It sets the level to INFO, and sends the log to STDOUT:

log = logging.getLogger()
log.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
log.addHandler(handler)

Maybe best in a config module?

Running Again

Most of the time, if I’m exercising regularly, I’m doing it for no more reason that to maintain and improve my health. For the last few months though, I couldn’t find the level of motivation I needed to stick to a routine. Maybe it’s the Polish winters.

Anyway, I realised that one thing would motivate me, and that was running a half-marathon again. I got a spot in the Great North Run, which I’ve done a few times before, and now I have a goal that I really want to achieve, that’s also going to require me to improve my fitness levels.

The run is in September, so I still have a lot of time to train. Good job too, because shortly after I got my place, I finally caught covid. Then after gently starting training, I got an overuse injury from moving a bunch of boxes. Still, I’ve stuck with it, and things are improving.

The biggest risks I can see to not completing it, the pre-mortem, are getting injured or losing motivation. I’m not too concerned about my motivation right now, but injury could be a real problem: painful to admit, but I really am a fat middle-aged man trying to reclaim some former glory, and ego might make me do something dumb. So I am trying to eat right, stretch properly, listen to my body… all the things I didn’t bother doing in my 20s!

I’ve used a Hal Higdon plan before, with great success. To make good use of the time that I have now, I spliced together a couple of his plans to cover the next 14 weeks. Behold, my Frankenstein’s monster of a plan:

W/C Monday Tuesday Wednesday Thursday Friday Saturday Sunday Weeks to Go
May 23 Stretch & strength 3.2 km run 30 min cross 3.2 km run + strength Rest 30 min cross 6.4 km run 15
May 30 Stretch & strength 6.4 km run 35 min cross 3.2 km run + strength Rest 40 min cross 4.8 km run 14
June 6 Stretch & strength 6.4 km run 35 min cross 3.2 km run + strength Rest 40 min cross 5.9 km run 13
June 13 Stretch & strength 6.4 km run 40 min cross 3.2 km run + strength Rest 50 min cross 6.4 km run 12
June 20 Stretch & strength 4.8 km run 40 min cross 3.2 km run + strength Rest 50 min cross 6.4 km run 11
June 27 Stretch & strength 4.8 km run 45 min cross 3.2 km run + strength Rest 60 min cross 7.3 km run 10
July 04 Rest 5.9 km run 3.2 km run or cross 5.9 km run Rest 40 min cross 8.1 km run 9
July 11 Rest 5.9 km run 3.2 km run or cross 5.9 km run Rest 40 min cross 8.1 km run 8
July 18 Rest 6.4 km run 3.2 km run or cross 6.4 km run Rest 40 min cross 9.7 km run 7
July 25 Rest 6.4 km run 3.2 km run or cross 6.4 km run Rest or easy run Rest 5-K Race 6
Aug. 1 Rest 7.3 km run 4.8 km run or cross 7.3 km run Rest 50 min cross 11.3 km run 5
Aug. 8 Rest 7.3 km run 4.8 km run or cross 7.3 km run Rest 50 min cross 12.9 km run 4
Aug. 15 Rest 8.1 km run 4.8 km run or cross 8.1 km run Rest or easy run Rest 10-K Race 3
Aug. 22 Rest 8.1 km run 4.8 km run or cross 8.1 km run Rest 60 min cross 14.5 km run 2
Aug. 29 Rest 8.1 km run 4.8 km run or cross 8.1 km run Rest 60 min cross 16.1 km run 1
Sept. 5 Rest 6.4 km run 4.8 km run or cross 3.2 km run Rest Rest Half Marathon 0

I almost followed the first week listed here, and I’m doing better at the second week. I’m tracking progress in a publicly-viewable Google doc, for myself and for accountability!

My real desire, if I dare name it, is to finish in under two hours. That may be too much to hope for given my current fitness levels, and I’d far rather jog the course in 2h15m than get injured training for 1h55m. But 1h55m would be very satisfying.

 

Update

I’ve survived dealing with the Polish social fund, ZUS (thanks almost entirely to my girlfriend), moved flat, redecorated, changed domain, dealt with tech support, and finally I am posting again.

This week I tackled the latest Riddler Express, and finished my 49th of the first 50 Project Euler problems. Just problem 26 left to go. It’s also the first anniversary of my starting to work from home because of covid. Strange year.