« first day (3978 days earlier)      last day (985 days later) » 

2:05 AM
Howdy y'all
 
cbgg
 
I was looking at this stackoverflow.com/questions/17261551/… question for the last couple days as I was working on a similar situation
I want to add some information, and wasn't sure if an edit to their answer, or a comment, or what, would be appropriate, but i decided a comment would probably be best; then I discovered that I'm unable to comment since I have only 35 reputation here on stackoverflow
in the first answer, where it says "DBSession().execute('EXPLAIN ' + query, {'param_1': 'value1', 'param_2': 'value2'})" -- i found that doesn't work, that you have to leave the str() off when creating the "query" item up above, and then that you have to use str(query.statement) there instead of just query; because otherwise bound parameters render as %(param_1) in your SQL, where the dbsession.execute(query, params) expects the query to have the bound parameter names represented as :param_1
anyway, because it took me all weekend and a lot of documentation-reading and trial-and-error to figure it out, i wanted to share it
 
2:44 AM
hello guys, I am trying to convert a column of a dataframe with a non standard format from string to datetime. my strings are in the format:
11/01/2021 12:00:00 AM

when I try pd.to_datetime( df.date) it converts it, but the resulting series doesn't have the timestamp, it only has the date. How do I convert it keeping the hh:mm:ss ?
 
 
3 hours later…
5:27 AM
anyone has worked on dash_tabulator?
If yes,
can anyone help me with that.
https://stackoverflow.com/questions/69011296/i-am-unable-to-use-cellclick-in-dash-tabulator
 
6:04 AM
Someone serial downvoted 10 of my posts...
 
6:21 AM
Cbg
 
cbg
 
6:42 AM
heyy'all
 
7:37 AM
kim chi
 
I have a question about the usage of super() here. I'm currently doing some exercises and I noticed this site uses super() in this way. Link: dpaste.com/HK384NQ4C
the commented code is where I tried out what I've learned, but nevertheless, they both returned the same result
Is there any difference between them?
 
cbg
 
@RoyalFrog Not in that situation, no. But Python can fill in the arguments automatically only in some cases, so at times there's a difference.
E.g. if you use super inside a list-comp, that's a different scope so Python cannot find the __class__ (which is only defined in method scope).
It's generally better (and the reason why it exists) to use the no-argument form because it's easy to pass the arguments incorrectly.
The PEP 3135 has some useful background information.
 
8:07 AM
Ohh okay, I see now, this new super is only available in Python 3.x, but then as you said, there's a difference in some cases. Will skim through that doc and thank you by the way.
 
 
4 hours later…
12:29 PM
Urgh. At times I want a big, red "make it stop" button for comments. It's amazing how unhelpful people trying to be helpful can be...
Incidentally, it's about super for added irony. :/
 
Hello Everyone,
I am a newbie trying to learn BDD framework i.e behave. I am stuck with apparently simple problem: using behave to take user input. I could not find any clear answer to that, does anyone here can give me some headsup?
 
 
1 hour later…
1:56 PM
@roganjosh. Thank you very much
 
 
1 hour later…
2:59 PM
Out of curiosity, is there any advantage using decimal instead of fractions for rational number math?
 
your excel loving "tech savvy" manager won't rage at you for using numbers that don't make sense.... that doesn't count? oh.
 
I am vaguely aware that at the edge of my reach, there be Users...
 
to be honest, i can't think of one right now. now, that doesn't mean one doesn't exist, but simply that i can't think of one.
 
3:53 PM
one thing in favour is fractions is that it's capable of handling cases where the result is say, 1/3, whereas decimal would be iffy with those
a friend of mine states that "decimal is needed to do lawful (literally lawful, as that is how the math is specified in law) financial math afaik"
 
hello everyone nice to see there
 
4:16 PM
@ParitoshSingh Where is this a legal requirement? That's a really interesting point
@BarışŞenyerli hello :)
FWIW one of our customers is asking me to calculate what their employees should be paid, and I'm vaguely concerned that there will be implications of how it's all calculated that might one day be in front of the HMRC. It's a layer of due-diligence that I'm starting to read around
 
4:43 PM
HMRC?
Her Majesty's Royal Commission?
 
"Customs"
Basically, whether the calculations need to stand up in court if the company ever required them to
See HMRC for avoidance of doubt
I think the responsibility lies with the customer anyway, but i'm not sure of the liability of a service-provider if we give them incorrect numbers
 
5:04 PM
Ah, income and other taxes. I see.
 
@ParitoshSingh I'm aware of not using float for currency because they aren't precise. But I would expect the same to apply to decimal as well, actually.
But it's been a while since I had to dig through that...
 
5:22 PM
@roganjosh im afraid i have no evidence to back this up, this was new to me too.
decimal should be precise for currency calculations, no?
 
I know that floating point errors can add up in surprising ways when you apply them to currency (and I'm not trying to lecture you on that or anything). It's curious that there's a legal standard
 
actually, my interpretation of that was different
i interpreted it as "financial math should have numerical calculations that have the mathematical decimals in them" (ie. even floats would be okay, but fractions would not)
let me see if i can get them to reply on what they meant
 
5:52 PM
@ParitoshSingh So my IIRC from Back Then is that if you are dealing with actual currency (what you would be billing someone), you use integers to represent small currency – e.g. 103 cent instead of $1.03. If you are doing actual math with currency, you take the most insanely precise machinery you can find and hope that no-one ever reviews it.
TLDR: Make science not money.
 
lol
and yeah, using ints for currency is always solid advice. but decimal doesn't suffer from the issues float does, ultimately, right? or to rephrase it, ints for currency is common advice, but is something explicitly wrong with decimals for currency in the context of python?
just got another response on that decimal vs fraction thing. verbatim "You have this flipped. There's almost never a reason to use Fraction. The advantage of fraction is that it has infinite precision for representing rational numbers, at the expense of infinite computation times for simple arithmetic and infinite memory. Using Decimal instead, you can represent irrational numbers like pi as well as rational numbers, by rounding them off to a significant number of decimal digits. ...
In real life (physics, engineering, biology, chemistry, etc), that's what's usually desired."
 
Well I can only assume that the microcents left on the cutting floor of decimal can add up to something.
 
but decimal shouldnt have microcents no
 
FWIW, back when I did True Science we had a printout of a histogram on the office walls that was showing some weird stepwise up-down. Looked like someone added a rectangular pulse on top of a gaussian.
It was actually from a real analysis that someone messed up by doing 32-bit calculations at the lower precision range before pumping them back up to the desired value range.
Whenever a new student suggested we speed up things by using lower precision, they had to accurately explain the plot.
 
haha yeah, floating point arithmetic is a gift that keeps on giving.
 
6:07 PM
@MisterMiyagi decimal is exact, yes?
it's kind of the whole point, so I'm wondering what I'm missing
>>> from decimal import Decimal
>>> Decimal(0.3) - Decimal(3)/10
Decimal('-1.110223024625156540423631668E-17')
Decimal is the "most insanely precise machinery". It's likely that fractions are too... so the question of preference is still valid.
I assume their APIs are geared differently
 
@AndrasDeak it's because you fed it a float. so 0.3 already introduced errors.
 
@ParitoshSingh yes, my point exactly
I guess it would've been clearer to avoid the first Decimal, sorry
>>> 0.3 - Decimal(3)/10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'float' and 'decimal.Decimal'
guess not
 
ah yep you're fine, i didn't realise the point you were trying to make till now
 
that's probably my fault :P
 
@AndrasDeak The default precision (on my machine) is "only" 28 decimal places. :P
 
6:12 PM
huh
 
>>> from decimal import Decimal as D
>>> D(0.3) - D(3/10)
Decimal('0E-54')
 
@MisterMiyagi I guess that's fair enough. So yeah, fractions are better.
decimals have finite precision so technically every decimal is a fraction
 
ooh, i didn't even realise decimals had a fixed precision
so yeah, if accuracy is paramount and you anticipate your calculations getting gnarly, fractions are just better then, no?
 
@ParitoshSingh it probably depends on what you want to do
 
@Paritosh not necessarily. From the fractions documentation: Note that due to the usual issues with binary floating-point (see Floating Point Arithmetic: Issues and Limitations), the argument to Fraction(1.1) is not exactly equal to 11/10, and so Fraction(1.1) does not return Fraction(11, 10) as one might expect.
 
6:17 PM
But if you know you're working with integer cents at worst then you can have either exact decimal dollars, or exact fractional dollars with a /100. And when you have many decimal digits then the equivalent fraction is ugly too.
@MattDMo that sounds like a different issue. That's fundamental to feeding floats to exact-math functions.
 
yeah with currency it's going to be really straightforward, decimal should be perfectly fine.
 
once you have 1.1 you already lost
 
@MattDMo that's a diff...er, kevin'd by Andras
actually with currency there's not all that big of a deal, you could just do int calculations, decimal calculations, or fractions. sane currency calculations would never need more than 2 decimal places.
 
So you need to start with whole integers going into Fraction() or Decimal() in the first place.
 
@MattDMo as it's always the case
 
6:19 PM
@MattDMo or strings are fine too
 
that too
 
@ParitoshSingh I don't know. Financial market calculations can get pretty weird
 
oh... hmm. okay, i suppose i dont know much about market calculations per se
 
Once you have percentages, all bets are off... I wouldn't bet that rounding to 2 decimal places is universal.
 
when i think finance my brain just thinks of like giving employees salaries and stuff. i have no imagination
 
6:21 PM
so you'll never be a day trader?
 
And when I think "market" I think people selling turnips.
 
@MattDMo or a night trader, if that's a thing
 
OK, this is the clearest I can do
>>> Decimal(1)/3 == Fraction('1/3')
False
 
actually, it is. They're the people that work crazy shifts monitoring markets around the world.
Global turnips
 
you can see how little i know because i totally did not expect that to exist, i just spotted an opportunity to make a terrible joke.
@AndrasDeak i.. uh.. what? o.o
 
6:23 PM
I know a little bit about a lot of stuff. That's how I've gotten so much rep :)
 
oh. the 1/3 thing. doh.
nvm ignore me. slow today.
 
@ParitoshSingh that's the crux of the issue.
@ParitoshSingh no
It's "decimal one third" being 1/3 only to n decimal places. Whereas "fraction one third" is exact.
 
Decimal can never represent 1/3 exactly
yeah, yep yep.
 
To be clear my "no" was a reply to an extrapolation of your question to "the 0.3 thing", which is different, because that's binary fractions and this one is decimal.
 
3 hours ago, by Paritosh Singh
one thing in favour is fractions is that it's capable of handling cases where the result is say, 1/3, whereas decimal would be iffy with those
 
6:25 PM
so yeah, the committee agrees that fractions are superior
@ParitoshSingh ah, yes, I missed that completely, sorry
 
all good! but yeah, i just said it and then forgot about it entirely :D
... which is probably worse.
 
The thing I've been wondering conceptually about fractions is whether they accurately represent a result… or just store the operation.
 
@MisterMiyagi do I need to fetch the Super Soaker?
 
I mean, if we add powers as operations then fraction won't be accurate, will it?
 
@MisterMiyagi how so? Raise both numerator and denominator to the power, right?
 
6:32 PM
As in, 2**0.5?
 
integer power, obviously
numerator and denominator have to be rationals
non-integer powers tend to mess with that
 
just played around with it, apparently fractions gives a float result if you use it with fractional powers. makes sense.
from fractions import Fraction

a = Fraction("1/2")

b = Fraction(2)

res = b ** a
print(type(res)) # float
 
I guess practicality beat purity
>>> third ** 1
Fraction(1, 3)
>>> third ** 1.0
0.3333333333333333
meh
 
7:20 PM
FWIW, the decimal module gives you fixed-point decimal numbers of a specified precision, and you can also choose a rounding scheme. The precision & rounding come from the context object. You can just use a global context, but it's easy to create new contexts, if you need them.
 
 
4 hours later…

« first day (3978 days earlier)      last day (985 days later) »