Thanks to visit codestin.com
Credit goes to github.com

Skip to content

added a timezone parameter to geonames#327

Merged
KostyaEsmukov merged 11 commits intogeopy:masterfrom
paulefoe:master
Dec 1, 2018
Merged

added a timezone parameter to geonames#327
KostyaEsmukov merged 11 commits intogeopy:masterfrom
paulefoe:master

Conversation

@paulefoe
Copy link
Contributor

@paulefoe paulefoe commented Oct 8, 2018

this fixes #163

Hey, it's been a while. I wasn't sure how to correctly implement this thing and I can see that there is a lot of work here to do. As far as an I can see, the timezone url is very different from geocode and reverse, however it has the same api as reverse, so I decided to put it there. I didn't write tests for this, for the same reason, I wanted to hear from you how are you seeing this timezone parameter?

@KostyaEsmukov
Copy link
Member

Hey, it's always good to see your PRs! I hope you're doing well.

Actually there's a related issue discussed in #326. I even think these two might be resolved at once.

As for the /timezone method, I don't think that it should be combined with the reverse method, because the returned data is semantically different. The plain reverse is intended to return a full address of the point, while the timezone is a different thing. In fact, GoogleV3 implements a similar functionality, so I think it could be used as an example here:

def timezone(self, location, at_time=None, timeout=DEFAULT_SENTINEL):

As for the /findNearby method, discussed in #326, well, I see at least two possible ways to implement it:

  1. As a new single choice-like (or a boolean?) parameter for the reverse method,
  2. As a new distinct method in the Geocoder class.

The first approach might look confusing (especially given that the two API methods, being called by the same single reverse function, have different sets of parameters), but it would allow to use the new API method with the other libraries/frameworks which assume that reverse geocoding can be done only one way (I suppose geopandas behaves this way).

The second approach might look cleaner from the geocoder's interface point of view, although it may still be confusing that a geocoder provides two distinct methods both doing reverse geocoding (it is confusing to me why geoname does actually provide so many different methods which could just be parameters for a single reverse method).

I haven't made up my mind yet on which way to go there, I would be glad to hear your thoughts on this one. I tend to incline towards the first option, yet I'm not certain about it. But anyway, this is out of the scope of the issue you're trying to resolve with this PR, so you may leave this out and work specifically on the timezone method instead.

@paulefoe
Copy link
Contributor Author

Hi again, sorry for the wait, I've been really busy lately.
I have a question for timezone. Is it okay to do it like this, because api supports some additional optional keys such as radius lang date, but if we will return pytz object they're useless.
For example here what it can return with a request like this:
http://api.geonames.org/timezoneJSON?lat=47.01&lng=10.2&radius=10&lang=ru&date=2018-01-01&username=demo

{"sunrise":"2018-10-18 07:40","lng":10.2,"countryCode":"AT","gmtOffset":1,"rawOffset":1,"sunset":"2018-10-18 18:27","timezoneId":"Europe/Vienna","dstOffset":2,"dates":[{"date":"2018-01-01","sunrise":"2018-01-01 08:05","sunset":"2018-01-01 16:40"}],"countryName":"Австрия","time":"2018-10-18 18:12","lat":47.01}

Same goes for findNearby, but I think it doesn't matter that much or does it?

@KostyaEsmukov
Copy link
Member

This is a great question regarding the other data returned by the timezone endpoint. I see the following options:

  1. Return a custom wrapper instead of pytz.timezone, something similar to Location, which contains a raw attribute.
  2. Move the actual implementation of the timezone method to another one, and make the pytz timezone construction in the current one, so the raw data could be retrieved by calling the second method.

I tend to incline towards the first option, but it would create inconsistency with the Google's timezone method.

I suggest you to just keep the pytz timezone for now. I'll reason about it before the release and will probably introduce the custom wrapper.

Copy link
Member

@KostyaEsmukov KostyaEsmukov left a comment

Choose a reason for hiding this comment

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

Don't forget that the new functionality must be covered with tests 😉!

@KostyaEsmukov
Copy link
Member

@Svalee I have just merged #332 which adds the aforementioned timezone wrapper. Could you please rebase your branch on top of the current master and use that wrapper in this PR?

@KostyaEsmukov
Copy link
Member

Hey @Svalee, do you think you could work on this before I'd cut the next 1.18 release? If not I'd be happy to take this over so this feature could be finally published. :)

@paulefoe
Copy link
Contributor Author

@KostyaEsmukov hey, yeah, I am very sorry about this, when is 1.18 release?
I'll work on this today and tomorrow if I wouldn't be able to do it today, is this fine?

@KostyaEsmukov
Copy link
Member

when is 1.18 release?

This PR is the main blocker, so as soon as it is merged.

I'll work on this today and tomorrow if I wouldn't be able to do it today, is this fine?

Don't worry, it was just a friendly reminder from my side. This is fine. :)

Copy link
Member

@KostyaEsmukov KostyaEsmukov left a comment

Choose a reason for hiding this comment

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

Thanks, I left a few comments below, could you please address them?

Also it would be nice to have the new changes of reverse method covered with tests. 😉

"lang": 'en'}
)

self.assertRaises(
Copy link
Member

Choose a reason for hiding this comment

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

Could you please refactor this to use the context manager interface?

https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaises

@@ -55,20 +55,62 @@ def test_query_urlencoding(self):

def test_reverse(self):
Copy link
Member

Choose a reason for hiding this comment

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

This test contains too many checks. Could you please split it to multiple distinct test methods?

self.assertEqual(loc.raw['adminName1'], 'Нью-Йорк')

with self.assertRaises(ValueError):
self._make_request(
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to use the raw self._make_request instead of self.reverse_run? If no such, please change to self.reverse_run.

Copy link
Member

@KostyaEsmukov KostyaEsmukov left a comment

Choose a reason for hiding this comment

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

Thanks!

Some things are still incomplete, e.g. _make_request is still being used, some versionadded directives are missing.

I'm going to merge this now as-is and will make the required corrections later, just to avoid the back-and-forth over some minor issues. The important parts are already implemented well, so it's a sufficient reason for this to be merged.

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.

add timezone to geonames

2 participants

Comments