filling holes connects unconnected islands


I’m trying to automatically fill holes in an “arbitrary” mesh. I first select all boundary vertices by using “Select non-manifold” and then enabling only “boundaries”. Selection looks typically like this:

After this I have tried to fill faces to boundary loops, and this is the result:

I really wonder why does Blender (I’m using 2.79 here) connect those unconnected islands together, and is there some command which would create faces to only connected vertex islands?

I’m trying to create a Python script which would automatically process and clean up these meshes for me, so I can’t rely on manual cleaning.

I have tried to use following Python commands for this filling stage, but all of them sooner or later create faces between completely unconnected vertices:




Please let me know if you have some idea what might be going on. Thanks!