bugpyFormex - Bugs: bug #42183, setProp acts both as method and...

 
 

bug #42183: setProp acts both as method and procedure!

Submitted by:  gianluca de santis <gianlucadesi>
Submitted on:  Thu 24 Apr 2014 01:18:14 PM UTC  
 
Category: CoreSeverity: 3 - Normal
Item Group: NoneStatus: Wont Fix
Privacy: PublicAssigned to: Benedict Verhegghe <bverheg>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 24 Apr 2014 02:52:02 PM UTC, comment #3:

I would not call this a procedure: it is an instance method that changes the instance. There is nothing wrong with that, if it is well documented ~)

Formex.append and Mesh.setType are other examples. There are some more, but usually not intended for the normal user (usually having a name starting with _). But the vaste majority of methods indeed do not change the object on which they are applied, thus your confusion is understandable.

I think the right way to obtain what you intend is your second suggestion:

It is so much more pyFormexic: more efficient and more clear to read.

Benedict Verhegghe <bverheg>
Project AdministratorIn charge of this item.
Thu 24 Apr 2014 02:36:44 PM UTC, comment #2:

One observation: is setProp() the only procedure in pyFormex? I only found _set_coords_inplace() that does the same. Should we add an inplace option as default, eg. setProp(inplace=False) ?

As a non-informed user to get a partition 'P' of a trisurface 'S' I did:

P = S.setProp(S.partitionByAngle()).selectProp(1)

and I expected that S did not change.

From now on I will do:

P = S.copy().setProp(S.partitionByAngle()).selectProp(1)

or

P = S.select(S.partitionByAngle()==1)

gianluca de santis <gianlucadesi>
Project Member
Thu 24 Apr 2014 02:01:08 PM UTC, comment #1:

This is the intended behavior.

I admit it is badly documented: the formex.py module states: these are the only functions changing the Formex: setProp, append.
But when the setProp was moved to Geometry, no mention of that special behavior was added to the documentation. We should do that.

The reason for the special behavior is that Geometry is often constructed without properties: it would be a waste to always add it by default. The setProp method then allows you to add properties to an existing Geometry.

Originally, setProp did not return anything. This was changed to return self, so that it could be used in a chain of operations, just like most other methods.

I think that this behavior is what is most practical for most users. If you want to set properties on a geometry and keep the original, you can use

This will create a deep copy of the Geometry, leaving the original untouched.

If what you want is shallow copies of a Geometry (i.e. same
coords/elems arrays, but different prop arrays), I think the best way is to handle this with a single Geometry, and keep a set of prop arrays external, then set the one you need, when you need it, with setProp.

Alternatively, you could create shallow copies with

Benedict Verhegghe <bverheg>
Project AdministratorIn charge of this item.
Thu 24 Apr 2014 01:18:14 PM UTC, original submission:

In geometry.py the setProp (which is a method of Mesh and Formex) acts as a class method, returning the object with new properties, but also a procedure, changing the object.

Check attached example.

gianluca de santis <gianlucadesi>
Project Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #31240:  setPropMethod.py added by gianlucadesi (1KiB - text/x-python)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by bverheg (Posted a comment)
  • -unavailable- added by gianlucadesi (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 24 Apr 2014 02:01:08 PM UTCbverhegStatusNone=>Wont Fix
      Assigned toNone=>bverheg
      Open/ClosedOpen=>Closed
    Thu 24 Apr 2014 01:18:14 PM UTCgianlucadesiAttached File-=>Added setPropMethod.py, #31240

    Back to the top


    Powered by Savane 3.1-cleanup1