As I understand here is the line of the code which causes an error. It expects string.
So try to pass python string explicitly
df.write_parquet("s3://my-bucket-name/my/path/to/file", partition_by='b')