Behavior of get_conjugate_plate_id()

When I use get_conjugate_plate_id (property_return=PropertyReturn.all), it returns the string all if there are multiple conjugate plate ids and the conjugate plate id if there is only one.
When I use get_conjugate_plate_id ([], property_return=PropertyReturn.all), it returns a list of conjugate plate ids or a list with one conjugate plate id if there is only one.

That the[] is required when using property_return=PropertyReturn.all and its behavior is not clear from https://www.gplates.org/docs/pygplates/generated/pygplates.Feature.html?highlight=get_conjugate#pygplates.Feature.get_conjugate_plate_id

What is your output if you run the following code?

import pygplates

feature = pygplates.Feature()
feature.set_conjugate_plate_id(1)
print(feature.get_conjugate_plate_id(property_return=pygplates.PropertyReturn.all))
feature.set_conjugate_plate_id([1,2])
print(feature.get_conjugate_plate_id(property_return=pygplates.PropertyReturn.all))

This is what I get:

[1]
[1,2]

If you get the same output then could you post some code (like above) that reproduces the problem. If you get a different output then there’s a bug somewhere (in which case can you tell me the pyGPlates revision and OS you are using).

In regard to the default parameter of Feature.get_conjugate(), it only gets returned if the condition fails (eg, no conjugate plate ID). Normally it’s just 0 so that calling:

feature.get_conjugate_plate_id()

…will return 0 if there is no conjugate plate ID.

But when you’re returning all plate IDs it’s best to explicitly set default to something you’d want returned back to you if there are no plate IDs, which is an empty list [] as you are doing with:

feature.get_conjugate_plate_id([], property_return=pygplates.PropertyReturn.all)

…so that the following code:

import pygplates

feature = pygplates.Feature()
print(feature.get_conjugate_plate_id([], property_return=pygplates.PropertyReturn.all))

…will give you [] instead of 0.

I get the same result as you with your example.
I tried different combinations and the one I reported intially shows up when leaving out property_return=.

feature = pygplates.Feature()
feature.set_conjugate_plate_id([1,2])
print(feature.get_conjugate_plate_id(pygplates.PropertyReturn.all))
print(feature.get_conjugate_plate_id(property_return=pygplates.PropertyReturn.all))
print(feature.get_conjugate_plate_id([], pygplates.PropertyReturn.all))

gives:

all
[1,2]
[1,2]

This does make sense as without the keyword pygplates.PropertyReturn.all is treated as the first positional argument, which is the default value. I sometimes forget computers are not as flexible as humans in recognizing where each argument should go :wink:

Great advice to set the default to a list, to prevent problems with sometimes returning a list and sometimes an integer. :slight_smile:

Oh I see, you had:

feature.get_conjugate_plate_id(pygplates.PropertyReturn.all)

…which specifies the first argument, as opposed to:

feature.get_conjugate_plate_id(property_return=pygplates.PropertyReturn.all)

…which actually specifies the second argument (named property_return).

I too trip up on that sort of thing with Python :wink: