6 ms·
I know some of the HN crowd are gonna wag their finger at me but the moment I have to deal with timestamps in Python, even for the most simplest of cases, I par
by iknownothow 3y ago
I know some of the HN crowd are gonna wag their finger at me but the moment I have to deal with timestamps in Python, even for the most simplest of cases, I parachute in pandas. `pd.Timestamp` (and its friends like `pd.Timedelta`) in my opinion are the most powerful timestamp toolkit available anywhere.
To me it's very often easily worth the extra 50-150MB of install size that just works. I've used pandas for around 7 years now and it was inconsistent and buggy at the beginning. But these days, it's practically flawless. Also I'm aware that pd.Timestamp is built on top of many awesome libraries.
- robertlagrant 3y agoI'm not a Pandas person - is it possible to install the Pandas timestamp functionality as a smaller library, or do you need to install the whole shebang?
- iknownothow 3y agoI had investigated if this was possible to do but I couldn't find a way to do it myself. It's possible that pd.Timestamp might be intricately tied interally to vectorization optimizations using numpy or others. Therefore separating out just the timestamp stuff from pandas would be a lot of work.
- dagw 3y agoPython is in many ways the anti-JavaScript when it comes to packaging. Where JavaScript will have a installable package that contains a single trivial function, Python packages will bundle hundreds of functions, all vaguely related to an area, with no easy way of just installing what you actually need.
- noitpmeder 3y agoMy experience has been exactly the opposite, with two exceptions: pandas and numpy. Generally every other library works in terms of standard python types where possible. Very few other places will you see things like a re-implementation of a time library.
- dagw 3y agowith two exceptions ...and scipy and all the scikit libraries and whole bunch of others. 'Accidentally' pulling in hundreds of MBs of libraries you never use for a 100 line data processing script is par for the course in python land.
- nerdponx 3y agoMy experience is that Pendulum does a good job of handling date/time data as a drop-in replacement for the standard library classes.
- FObersteiner 3y ago> pd.Timestamp is built on top of many awesome libraries ... pytz for example ;-)
- orthoxerox 3y agoYes, and? Doesn't mean it inherits all the usability flaws of pytz.
- FObersteiner 3y agoNo, I think pandas actually abstracts away pytz's footguns, so that's a good thing.
- marcosdumay 3y agoAs long as it hides the footguns, you are good to go. Pytz is not technically flawed.
- pganssle 3y agoWell, pytz actually is technically flawed at the moment because it cannot read TZif Version 2+ files, so it breaks for dates >2038 (and it would break if you tried to point it at system data generated with zic's "slim" mode), see this: https://github.com/stub42/pytz/issues/48 https://github.com/stub42/pytz/issues/48 But you are right that pandas' use of pytz is benign and as far as I know doesn't suffer the same usability issues.
- irjustin 3y agoPendulum is quite good[0]. Relatively intuitive interface. When I left Rails, this is one area I really missed. Time.use_zone("Singapore") { (Time.zone.now - 3.days).beginning_of_week } This readable line in datetime utils or even pendulum, is such a pain. [0] https://github.com/sdispater/pendulum https://github.com/sdispater/pendulum
- ttymck 3y agoHow does the rails example work? It must be using a global/shared state?
- irjustin 3y agoSorry I'm a bit confused by the question could you elaborate?
- wussboy 3y agoI've been using pendulum heavily in production for over a year now and it has made my life very much simpler. It's a great library.
- jstx1 3y agoHandling timestamps well was one of the motivations for building pandas in the first place (Wes McKinney started pandas while he was working at an investment management company).
- arcanemachiner 3y agoDjango has similar functionality: from django.utils import timezone now = timezone.now() later = timezone.now() + timezone.timedelta(minutes=1)
- deleted 3y ago[deleted]