Skip to content

Modified approach for time init additions - #6

Merged
eteq merged 2 commits into
eteq:time-init-additionsfrom
taldcroft:time-init-additions
Dec 4, 2012
Merged

eteq merged 2 commits into
eteq:time-init-additionsfrom
taldcroft:time-init-additions

Conversation

@taldcroft

Copy link
Copy Markdown

Good idea to allow for initializing the Time object with an existing Time object.

There is an existing method Time.replicate(self, format, copy) that makes a reference copy or deep copy (copy=True) of a Time object. I used this method within a new Time.__new__ method to take care of the copying bit when val is a Time object. The main benefit of this approach is that all the other Time initialization keywords will now function as expected, i.e. format, scale, precision, and so on.

Also added code to do the same in TimeDelta.

Comment thread astropy/time/core.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want this indented? That is, if you're using replicate you don't want to run the initializer, right? Or is the idea that you want it to still run the initilizer for some reason I'm not understading?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it still should run the initializer so that the rest of the attributes (e.g. lat, lon, scale, precision) get set in __init__. If the return self line were indented then the replicate case would return None as the new Time object.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see - I misread this and was thinking in the if statement you meant to return something else, but I now see that it gets set to self as well.

@eteq

eteq commented Dec 4, 2012

Copy link
Copy Markdown
Owner

Thanks @taldcroft - now that I understand the deal with __new__, it looks good to me - merging!

eteq added a commit that referenced this pull request Dec 4, 2012
Modified approach for time init additions
@eteq
eteq merged commit a719712 into eteq:time-init-additions Dec 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants