« first day (3181 days earlier)      last day (1992 days later) » 
00:00 - 17:0017:00 - 21:00

00:18
@AaronHall This is a really good read, especially if you like seeing CS theory in practice. Written by the man himself. python-history.blogspot.com/2010/06/…
A diamond problem came up at work and after reading this I was well-equipped to solve it. One of the more interesting things I've seen.
01:04
cbg
 
1 hour later…
02:28
recbg
 
1 hour later…
03:41
cabbage
 
2 hours later…
user10984358
05:54
I have two python files using the PyQt5 GUI, one that has the main application and the other that just reads a csv or excel and displays it as a table in a PyQt Widget, is there anyway I can make these two files as one? Because the class used in the second program is derived from QAbstractTableModel where as the first one derives from QWidget
user10984358
class PandasModel(QtCore.QAbstractTableModel):
    def __init__(self, data, parent=None):
        QtCore.QAbstractTableModel.__init__(self, parent)
        self._data = data

    def rowCount(self, parent=None):
        return len(self._data.values)

    def columnCount(self, parent=None):
        return self._data.columns.size

    def data(self, index, role=QtCore.Qt.DisplayRole):
        if index.isValid():
            if role == QtCore.Qt.DisplayRole:
                return QtCore.QVariant(str(
user10984358
that is the second application code, the other one is pretty much a normal GUI
06:59
Hi guys
I have a pandas dataframe
I have a city column and a roads column
I want to display samples of 2000 across all cities
How do I do that?
So I have around 807 unique cities so I know that some cities has to be repeated since the no of samples is more than 807
However the main thing is I need to represent all the cities
07:31
There are other columns as well but for now I am just taking the sample of roads across cities
@TheNamesAlc - usually preferred to put large code chunks in pastebin and link to them. Why the "need" for a single file, just as a matter of interest?
No problem with putting them together - Python doesn't require one-file-per-class.
to be exact, a set of 2080 elements, which you can easily reach for real-life problems
as a PhD student embarrassingly "demonstrated" to us...
I also tried looking at this solution:
6
Q: Stratified samples from Pandas

HonzaBI have a pandas DataFrame which looks approximately as follows: cli_id | X1 | X2 | X3 | ... | Xn | Y | ---------------------------------------- 123 | 1 | A | XX | ... | 4 | 0.1 | 456 | 2 | B | XY | ... | 5 | 0.2 | 789 | 1 | B | XY | ... | 5 | 0.3 | 101 | 2 | A | XX | ......

However what it does is get n samples of each unique record grouped by
So if I want a sample of 2000 across all cities it would give 2000 * 807 if all of them had atleast 2000 records
But what I want is 2000 total spread across all the cities
It would be good if anybody can help as quick as possible because I need to give this data in 30 mins
07:58
@MisterMiyagi I suppose so. But it's going to take a while to print all those permutations. ;) If you need a longer period it's not that hard to use the random module with a longer period PRNG. The docs link to a Complementary-Multiply-with-Carry recipe with a period of 3636507990 * 2 ** 43487 (approximately 10 ** 13101) or just use SystemRandom if you don't need a seed (and have an adequate entropy pool).
FWIW, I estimated that figure of "over 2000" in Google calculator, using Stirling's formula for factorial. I do have code to invert log factorial, but I couldn't be bothered booting up my computer. :)
You can see my inverse log factorial code here. It's rather old, so it's in Python 2. Sorry about that.
09:00
she was using it for an optimisation problem, basically traversing permutations until a perfect one was found
so there wasn't really a boundary from printing permutations, since most were discarded immediately
there was just a "completely unexplainable slowdown" for large n, and the solver would just stall at some point and behave "as if it was an infinite loop"
simply using ``itertools.permutations`` gave deterministic runtime and reliable halting, as well as being considerably faster
TLDR: using random to generate permutations is on my list of patterns to terminate on sight
@PM2Ring I'm old enough to appreciate it even in Py2 :P
surprisingly enough, it is not
though now I am tempted to try...
09:34
@MisterMiyagi Wise. Of course, it's fine if you just want a small number of permutation, like shuffling a deck of cards. But it's definitely not good if you need to generate all the permutations of a list. If you need those permutations to be generated in a random-looking order, I guess you can just shuffle the base list. Or generate each permutation from a sequence number & a randomizer seed, using format preserving encryption, eg stackoverflow.com/a/51429458/4014959
I think using random to generate sequences is just a bad substitute for having to program permutations. In python there's no excuse.
Cbg
@AndrasDeak it seems strange to use random for permutations, which might never generate them all, or do some twice, vs just iterating through all the permutations once
Oh sorry, everyone agrees with that
burrows
I'm sure plenty of newbies who don't know about itertools have used random to make permutations. And that's ok if you just want a few, but it's insane if you want all the permutations. Especially if the total number of permutations is larger than the period of your PRNG. :) But even for small numbers it's silly. If you want all 120 permutations of 5 items, the last few will take ages to churn out randomly. Relatively speaking.
09:49
that's the problem, most people start with a small test set and see that it works fine
when they throw it at larger problems, it suddenly behaves "weird" and they don't know why
I've seen all sorts of strange theories for such unexpected performance degradations
OTOH, if you want to permute a collection with repeated items, itertools.permutations sucks. Fortunately, there's an efficient algorithm from the 24th century that does handle repeated items. See stackoverflow.com/a/31678111/4014959
We all here livin' in 2019 while PM livin' in 2319
Oops. I meant the 14th century. :)
Thanks, mystery upvoter. ;) I'm not fishing for votes, just sharing some algorithms I think are nice. But upvotes are nice, too. :)
(I need to write another good answer or two on Physics. I thought my last few were ok, but they didn't net any score. But I've been busy downvoting bad answers, and I don't want my score to drop too low.)
10:36
@PM2Ring I'm a sucker for anything involving hash functions, and your answer was worth it
Thanks!
10:51
If you like hash functions you might enjoy my ramblings about hash functions and the avalanche effect, around here:
Aug 6 '18 at 19:33, by PM 2Ring
But these hash functions are full of inscrutable magic numbers. Simple bitmasks like F8 are the familiar friends in a sea of mystery. Eg, here's the final mixing phase from the 32 bit version of the popular Murmur3 algorithm:
11:05
@PM2Ring thanks, now I can check of my "learn something new" for today
user10984358
11:17
@holdenweb i thought that was the only way you can make the table a part of the GUI, if I can access that class's widget within my class then it is fine, my end result is having that table within the main GUI. Since the main class inherits from a different class I am confused as how I can make that widget appear in this.
11:41
You though what was "the only way to ..."?
You are constructing a whole QApplication to create and display the table. do I take it you'd like some action on the main GUI to display it as part of a larger application?
@piRSquared And since you fast whenever you stop eating, EVERY meal is breakfast.
@thena Since the QTableView is a QWidget it's fairly easy to incorporate it as a component into a GUI. from that point of view it hardly matters whether you define it in the same module or import it from another one. but I have a feeling I'm not understanding what you need to achieve.
Nothing more certain to induce typos than a UI message saying "you have less than 5 seconds for editing" ...
@TheNamesAlc: ^^^
basically, they're all QWidgets. Given a reference qw to a QWidget, you can add it to a VBox or Hbox box with box.addLayout(qw). This can be done dynamically, not just at UI initialisation time. does this help?
Man, don't know what it is about today but I'm seeing some really yammed-up answers getting upvotes today. Forgive them, for they know not what they do.
For example, stackoverflow.com/a/56851315/146073 seems to offer little help, or am I just being my customary chrochety Foul Ole Ron self, bugrit?
12:10
looks like the job for a Queue or deque, actually
cbg
Is there a canonical for subclassing builtins, or collections objects?
I found https://stackoverflow.com/questions/2673651/inheritance-from-str-or-int/2673863#2673863, but I am thinking there must exist more detailed answers.
a canonical what?
a canonical answer detailing the proper way of doing it, the pitfalls, and things to pay attention to.
cbg
wow 33 users here
Time to talk
12:20
a canonical answer that one can dupe-hammer to
you can subclass builtins just like anything else, with the exception of some obscure helpers like ``slice``
it really depends on what one wants to do in specific
most of the time, people actually want composition, not inheritance
@ReblochonMasque do you have a specific question in mind?
if you mean stackoverflow.com/questions/56850716/…, the problem is confusing __new__ and __init__
that is not an issue of builtins, just not knowing the type one inherits from
I don't subclass builtins much. What are the pitfalls etc that distinguish it from inheriting from non-builtins?
If the answer is "it depends on what builtin you're inheriting from, they all have their own unique interfaces", it's going to be a challenge finding one answer that encapsulates all of them
Yes @MisterMiyagi, that is a specific question! The info to be found on subclassing both builtins and collections objects is sparse, and usually non-authoritative.
since that depends on the type in question, there really is no canonical answer for all builtins
I agree @Kevin, the answer will be different for different classes. Yet, knowing that does not make answers appear - are there or not canonicals as described above?
If yes, where are they?
12:27
oh damn my internet is super slow
If not, then we probably need them.
I did not ask for one answer for all builtins @MisterMiyagi !!
I have not personally seen any such canonicals.
Okay, thank you @Kevin.
I believe there should be; I have needed some sort of guidance a few times, and never found what I was looking for.
@Kevin I imagine a subset of issues comes from the class being implemented in C
The real problem with subclassing the builtins is that the minute you delegate to a builtin's method you get a return value which is of the superclass's type rather than the subclass's. This leads you into an ever-more-complex ladder of reimplementation until you might just have well written it from scratch.
12:32
@ReblochonMasque isn't that what "canonical answer for subclassing builtins" implies?
The issue being that the C builtin methods aren't (and indeed probably coudn't be) built to cooperate fully with the interpreter's inheritance mechanisms, because they don't use the equivalent of self.__class__(...) to build the results.
I suppose it's not impossible to write a series of canonical posts of the form "How do I subclass (int/float/str/bytes/tuple/list/dict/set/array/defaultdict/Counter/decimal/...)?", but that's a pretty substantial undertaking. And I'm so very tired.
You are in an arguing mode @MisterMiyagi LOL
Leave it to those who aren't aware of the pitfalls. good sniping practice later ;-)
Thanks @holdenweb, this is the sort of things needed.
12:34
@MisterMiyagi Although you put "canonical answer for subclassing builtins" in quotation marks, you were the first person to use the phrase when you did so.
What holdenweb said there. Especially with immutables. Eg, if Mystr inherits from str, all the inherited methods that return a string continue to do so. If you need the to return a Mystr then you have to implement all those methods, calling the super method and then convert the result to a Mystr instance.
Which is about as much fun as writing the class from scratch.
@holdenweb I was referring to Reblochon's "canonical for subclassing builtins" above, with a missing word filled in
I wonder if you could do something underhanded with __getattribute__ to make sure arithmetic on your custom type always returns an instance of that type.
Are the UserXXX (such as UserDict and UserList) still a thing?
12:36
hi pyhtoners
@Kevin It seems that when I have tried overriding dunders on builtin classes, my sub-dunders never get called
IIRC there is an answer on how __init__ and __new__ react to being overridden separately
@Kevin i won't say no. I'll just say "I very much doubt it." This is a problem on which much brain power has already been expended, so the probability of a novel solution is low but not zero.
Hmmm, this code does give 1 as a value:
class Zstr(str):
    def __len__(self):
        return 1

z = Zstr("abcdef")
print(len(z))
12:39
@PaulMcG What's wrong then...
@HasanKucuk hello
OK. now let's see what __add__ looks like. Then tell me why you have to implement __radd__, and what that returns.
@U9-Forward This:
print(type(z.strip()))
print(len(z.strip()))
gives 'str' and 6
Yup. Any method inherited from str that returns an str type will continue to do so.
@PaulMcG Your code isn't modifying the string __len__ and __type__ objects...
12:41
@U9-Forward :|
Which is actually almost a direct quote from @PM2Ring above, I now observe.
@U9-Forward We were discussing inheriting from builtin types and overriding method, not monkeypatching the builtin
Hmm, I think "[__getattribute__] may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or built-in functions" torpedoes my master plan
I reckon there's good grounds to have some canonical answers for this stuff. Existing answers may be obsolete, or at least no longer best practice. There are Python 2 answers from before the UserXXX classes existed, as well as after. And those classes have been moved to collections.abc in Python 3, although they are currently still accessible with a collections import, although that's deprecated.
@PM2Ring I'm pleased to hear there's a Wikipedia article for this. Now that I read it, I remember it being discussed in here a long time ago. Would have saved me some labor if I could have recalled that before the fact. But then I wouldn't have had a fun puzzle to solve.
12:48
obligWP
@Kevin Yeah, attribute lookup on builtins is rather different from attribute lookup on user-created types.
Thank you for your support @PM2Ring
@ReblochonMasque I'd like to understand exactly what is needed since this is very easy to get wrong
okay @MisterMiyagi, I understand.
>>> int.__le__
<slot wrapper '__le__' of 'int' objects>
12:53
Found a builtin inheritance pitfall:
class Thing(int):
    def __repr__(self):
        return "Thing"

print(Thing())
#result:
#0
I thought "canonical" expressed it, but it is clear that I need to be more specific and detailed.
@Kevin I posted some code for the generalised coupon collectors problem on xkcd about 10 years ago. I won't link to it. It uses brute force, since I didn't know the generalised formula back then - my code was written to help search for patterns that would reveal the general formula. I did find some patterns, but not the formula. The code is rather ugly: I didn't know itertools, and it fabricates a dynamic number of nested for loops (up to 30 levels deep!) using exec. :blush:
@Kevin Reproduces superclass behaviour exactly.
>>> print(int())
0
Unfortunate, isn't it?
I don't mind that my Thing has a value of zero, but I do mind that it's ignoring my method
I think you are getting the result of __str__ here. Try print([Thing()]) or just print(repr(Thing())) to be sure you are repr'ing instead of str'ing
12:56
Is there a way to save a copy of this discussion?
@Kevin Success below:
>>> class Thing(int):
    def __str__(self):
        return "Thing"
    def __repr__(self):
	    return self.__str__()


>>> print(Thing())
Thing
>>> Thing()
Thing
>>>
@ReblochonMasque There's a feature to save conversations, but it would be globally visible to all users, and anyone (or maybe just ROs) could delete it at any time. The only permanent solution is to bookmark a permalink of the first message you're interested in.
Noted, thanks @Kevin
@ReblochonMasque But feel free to save the conversation. Go to the room menu up in the top right of the page, and the 2nd menu item is "Create new bookmark"
@U9-Forward Oh, so it's less of a "builtin types are weird" problem and more of a "print checks __str__ before it checks __repr__ so if you're inheriting from a type that implements __str__ then you can't change print's behavior just by overriding __repr__ and not __str__" problem.
13:01
@Kevin only mods can delete...
@Kevin Yeah it's strange
Got it @PM2Ring, very helpful.
Thanks
@AndrasDeak Oops. In that case, since us ROs have no ability to curate the conversations list, it's even more important that everybody be extremely very certain that the conversation they want to enshrine is exceptionally interesting and useful to a broad audience and will remain so for the indefinite future.
proliferating like mushrooms
13:04
"Initial thoughts regarding a canonical post about overriding int" does not quite meet those standards, in my opinion
@Kevin I would probably describe this as the "my code didn't get called because I didn't override the right method" problem
@PaulMcG See, this is how you know I never use inheritance: I just assume that implementing repr by itself will work. Because it does always work if the class doesn't have an explicit parent.
My internet sucks
@U9-Forward We feel your pain. But you don't need to keep telling us.
@Kevin falling back to __repr__ is part of object.__str__: github.com/python/cpython/blob/…
it is not a general rule
13:06
@PM2Ring okay, this is the first time it's telling me "Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load."
I blame docs.python.org/3/reference/datamodel.html#object.__repr__ for not making it clear that 'If a class defines __repr__() but not __str__(), then __repr__() is also used when an “informal” string representation of instances of that class is required.' is a consequence of object's implementation and not because of something in Python's internals
in general, the docs never rarely assert the difference between what the Python VM does, the object model and object itself
Oooohhhh that's a treasure trove @PM2Ring :)
@Kevin print calls __str__. And Thing inherits both a __str__ & __repr__ from int, so you need to override __str__. If int didn't define __str__, thenThing.__repr__ would do the needful.
(Yam. All those dunders are a pain to type on mobile.)
Anyway, my __getattribute__ scheme is thoroughly foiled:
import abc

class FancyInt(int):
    def __getattribute__(self, name):
        print(f"__getattribute__ was called with name {name}")
        return int.__getattribute__(self, name)

x = FancyInt(2)
print(x)
print(x+2)

#expected output:
#__getattribute__ was called with name __str__
#2
#__getattribute__ was called with name __add__
#4

#actual output:
#2
#4
13:12
you need a new metaclass for that to work
since special methods are looked up on the class, the class' class' (aka metaclass') __getattribute__ would be used
not sure if Python VMs cheat, though
So str can fallback to calling __repr__ if __str__ doesn't exist (somewhere in the inheritance chain), but it doesn't work the other way around.
OTOH, I can't recall seeing a class without a __repr__, since by default you inherit it from object.
You had my worrying for a few seconds @MisterMiyagi :) I'm sure I tested all the permutations of this a few years ago. And IIRC Martijn (or maybe a core dev like rhettinger) wrote an answer about it.
sorry, I confused the C function names
No worries.
13:35
Mildly baffled by the presence of "O(1/N)" in the formula at en.wikipedia.org/wiki/…. Don't think I've seen that in a context other than time/space complexity.
we use abominations like 0(1000), if that helps :D
It's for any kind of asymptotics
@MisterMiyagi noooooo
Perhaps I'm supposed to interpret it as "some function that we haven't formally derived yet, but which definitely doesn't grow any faster than 1/N does"
(give or take a constant multiplier)
Stirling's formula that I used yesterday is log N! = N log N - N + O(log N)
@Kevin indeed
I used stirling's formula yesterday to calculate the complexity of that one problem. I think I incorrectly handwaved away too many components, but oh well.
13:42
Thanks y'all for your input on the subclassing of builtins and collections objects, that was instructive.
after some testing, it seem that overriding ``__getattribute__`` in the metaclass is not enough either
either ``type`` is cheating, or the VM is
I stopped halfway through bootstrapping my own ``object`` and ``type``
o, O, and theta just tell you there's a majorant, minorant or both with the sequence inside the argument
In the category of endofunctors, of course
user10984358
@holdenweb when I select a file using the browse button created, the code block for reading a data frame is executed and then the table is supposed to be dispalyed
@AndrasDeak for some reason, I read that as "major rant or minor rant or both"
13:44
Knowing me that's hardly surprising
@holdenweb now we're talkin'
@Kevin I can explain if you're not just joking
@piRSquared reply to what? Why won't you use replies?
I'm half joking. I don't know the terms majorant/minorant, but I think I can guess their meaning from context.
Yeah, just ≤/≥ c*other_sequence for some c
@holdenweb ^ was reply to this
13:49
There's always an ounce of truth behind my "doesn't get it at all" goofs, but I usually fire them off before I've done my due diligence to try to learn what they mean on my own. In other words, you shouldn't feel obligated to teach me the concept at that time, because I haven't earned it yet.
don't hold back
there are some lurkers who enjoy the discussion
On the other hand, teach me stuff whether I've earned it or not, if it brings you enjoyment
@Kevin I think majorant is a vegetable oil based spread for toast while minorant is similar but with less trans-fats.
Something something Ant-Man
14:00
Oh, I thought majorant was a somewhat cold-sensitive perennial herb or undershrub with sweet pine and citrus flavors, sometimes synonymous with "oregano" in middle eastern cultures.
Minorant is the twitter handle of the half-bull half-man that protects the Labyrinth. He has very strong opinions about border walls.
(Unclear to me whether the Minotaur would be pro-wall or anti-wall. How does he feel about living within the walls of the Labyrinth? Does he consider it his prison, or his domain of power? Must one imagine the Minotaur happy?)
He was put there because his dad was ashamed I think...
So probably not crazy about it
Atlas experiment live at CERN - facebook.com/cern/videos/2333497466917439/…
@PM2Ring
Or was he another of Zeus' bastards and it was the stepdad who was unhappy?
@ReblochonMasque also total eclipse soon
14:14
Where about the eclipse?
What piR said. Expert on circles of all kind.
He's the offspring of Pasiphaë and the Cretan Bull, who doesn't have an affiliation with Zeus, despite the latter's prediliction for turning into animals
@ReblochonMasque America ;)
Pasiphaë's husband Minos put him in the Labyrinth. I guess you'd call him the stepdad.
Ah, OK, thanks
14:16
I saw the total eclipse in China in 2009 or 10.
I cut up my shoulder xrays to protect my eyes O_o
Is that a safe method, UV-wise?
en.wikipedia.org/wiki/Solar_eclipse_of_July_2,_2019 gives a complicated chart that I assume shows the ideal viewing position on the globe for the eclipse
For best results, view from the Pacific ocean, due south of Arizona and due west of Chile
IDK @AndrasDeak - I can still see.
14:21
IIRC, UV damage is pretty apparent in the short term, so you're probably OK
I guess so. Like arc welding.
Though I think UV can cause cataracts in the long term
Oh yes. Get a flash from an arc welder and you'll be crying for a couple of hours. Eyeball radiation burns aren't very comfortable. I speak as one who saw this happen to a classmate when we were learning to arc weld.
Maybe I'm thinking of retinal damage due to regular visible light. If you don't see spots immediately and persistently, you're good.
@holdenweb also retina damage?
The medical information I glean from wikipedia is muddled at best, let's be real
14:29
Probably cancer
Not from a single flash.
If you're saying "every online source of medical info inevitably tells you that you have cancer, no matter what the symptoms are", yeah.
Of course given the nature of the inverse square law, a lot depends on the distance. Don't know about retinal damage.
That's why I work backwards. I look up the disease, and read the symptoms, rather than looking at symptoms to see what diseases cause them.
@AndrasDeak It's not ideal, but if the x-ray is fully exposed it's not too bad, since the metallic silver is ok at limiting the UV. But I don't know how many layers you need.
14:32
@holdenweb I thought that's the primary cause of welding blindness
@Kevin yeah. I'm just overly terse, typing on my phone from a protest :D
@holdenweb wise!
But for this eclipse, totality in South America occurs about 40 minutes or less before sunset, so the angle is low, and hence the UV risk is much lower than for a midday eclipse.
haha, what are you protesting against @AndrasDeak
Initially read that as "typing on my phone as a form of protest"
Down with desktop PCs!
Thanks - yes, Hungary and Poland are pushing the envelope here.
I support your protest.
Thanks, it won't matter.
I mean the protest; not your support :P
Fred Espenak is the eclipse guru. He made the chart on Wikipedia. Here's his page for this eclipse eclipsewise.com/solar/SEprime/2001-2100/SE2019Jul02Tprime.html Elsewhere on his site you can learn what that chart means. :)
It's unclear to me how, on the graph at eclipsewise.com/solar/SEhelp/SEpingkey.html, the sub-solar point is north of the southern limit of the penumbra. If the sub-solar point marks the vantage point where the moon doesn't occlude the sun at all, and the penumbra is the partial shade due to the partial occlusion of the sun by the moon, how can they overlap?
Theory 1: I misunderstand one or both of these meanings. Theory 2: occlusion only counts if the moon overlaps the main body of the sun, and the moon can still cast a penumbra if it overlaps the sun's corona.
> The subsolar point on a planet is the point at which its sun is perceived to be directly overhead;
14:50
Theory 1, then.
The penumbra's edge should exactly tell you where there's no occlusion
I guess the point of greatest eclipse and the subsolar point only coincide when the sun, earth, and moon are exactly collinear
I call this a super duper total eclipse, or Kevin's Eclipse
I can't find a wikipedia article for this concept so I assume it's exeedingly rare to the extent that it's never happened in human history and isn't predicted to happen in the future as determined by our best models
Or maybe I'm just bad at googling.
I would argue that any total eclipse at maximum has to mean the sun, moon and earth are collinear at the subsolar point. But maybe I'm as bad at geometry as you re at googling.
A total eclipse implies that a line drawn through the centers of the sun and the moon will intersect the surface of the earth. A Kevin's Eclipse requires that line to intersect the Earth's center.
15:05
@Kevin I was using a spherical approximation of the Earth, under which all normals to the surface go through the centre.
@holdenweb no, as per the image Kevin linked
Note I said "at maximum"
Note that even a Kevin's Eclipse may not be total, it can be annular. So for a truly maximal eclipse we need a Kevin's Eclipse to occur when the Earth is at aphelion and the Moon is at perigee.
Perhaps that's slightly too strict of a requirement for a total eclipse. If totality occurs a little bit after the sun is halfway done setting, then the sun-moon line will barely miss grazing the earth. But it still counts as a total eclipse, I guess?
A robust definition would require, like, the intersection of cones and spheres and stuff, which is beyond my powers as an armchair geometer.
As so often turns out to be the case, on reflection and after discussion I find my position completely untenable.
15:09
And near sunrise & sunset the atmospheric refraction is pretty large, so the lines get a bit bent.
Right. The sun has actually gone below the horizon abt seven minutes before we see it set, IIRC.
About that, I can't remember the numbers, and it depends on the latitude & season. Near the equator, the Sun's apparent path makes a fairly large angle to the horizon, so twilight is rather short. At high latitudes, especially in summer, twilight can last for hours because the Sun's path makes a very shallow angle with the horizon.
IIRC, about 20 years ago there was a weird solar eclipse where the path of totality just grazed Antarctica around 4AM during the southern summer.
I expect July 16, 2186 is the closest we'll get to a Kevin's Eclipse for a long long time
"At high latitudes, especially in summer" Or maybe that should be winter. I was up at 5AM, and I'm getting too tired to visualise this stuff. ;)
Not sure whether that article's projected timeframe of "[longest eclipse until] at least AD 6000" means "an eclipse will happen around AD 6000 that will be longer" or "we didn't/couldn't simulate any eclipses past AD 6000"
I'm guessing the latter, because if there was a super long eclipse in AD 6000, it ought to have an article too
15:20
yeah, that's what it sounds like
Foiled by the N body problem once again
And/or the fact that real planets aren't point masses so even if you had a really good N body algorithm you probably wouldn't be able to accurately model the state of the solar system in the far future anyway
Foiled by the general concept of chaotic systems once again
OP asks "How does this code work?" What reason should I use to close?
We can probably do fairly accurate eclipse calculations past AD 6000, but mapping them to the exact position on the Earth's surface is a bit tricky, due to the tiny irregularities in the Earth's rotation. The Moon's orbit is very complicated, but due to the lunar ranging data we have really good parameters for its orbit, currently accurate to a few centimetres.
hmmm, it's missing a MCVE but isn't quite "why isn't this code working". Maybe "unclear what you're asking"
@piRSquared Is it their code, or some random code off the net?
@PM2Ring not sure
Probably an RA or student who inherited a project from someone else and now they need to clean some more census data
An unresolved question in the definition of Kevin's Eclipse is how much wiggle room is allowed for collinearity. If you demand sub-centimeter accuracy, then our current models can't say for certain whether any eclipse is a Kevin's Eclipse. If you only require accuracy on the order of thousands of miles, then every total or annular eclipse is a Kevin's Eclipse. Gotta find that happy medium.
They're using the US_ANNUAL_ESTIMATES2010-2017.csv file.
or something very close, that one doesn't have CTYNAME
15:38
@piRSquared I guess it could also be a hybrid: code they found & modified, but they don't understand how the core works. I have some sympathy for such OPs, since they're trying to transition away from cargo-cult coding. But as Martijn says, unless they can ask a clear focused question, that indicates what parts of the code they *do understand, and enough info for us to judge their knowledge level so we can write an answer that they'll understand, then the question's unclear, or at least too broad.
wim
wim
40
Q: When did SO turn from "A site for professional and enthusiast programmers" to a "Help me with my school works" site?

TheGeneralI have been active on this site for many years, yet I have never seen the level of programming questions so rudimentary as it has been in the last 12 months. Yeah sure, there has always been beginners asking questions, yet something seems very different in the last 12 months or so…. A demographic...

stackoverflow.com/a/55829147 low quality, no new information, no explanation
I'm trying to make a code injection with python.
I get an error when I use a method like the following to change the package.
When I replace the package.set_payload (bytes (new_paket)) in my method with this code packet.set_payload (bytes (new_paket, 'iso-8859-1')) I get the following error.
Python version: 3.7.2
Scapy version: 2.4.2

I tried the solutions in Stackoverflow again, it gives an error.
wim
wim
I thought asking the room for downvotes was against room policy?
@HibritUsta welcome, please use a paste service like dpaste.com to post large blocks of code
be sure to include the full traceback as well, not just the last line
15:53
Well I am correcting.
@wim Correct. But that answer needed killing. ;)
I guess we could've posted a comment explaining why we deleted it...
user10984358
can I one hot encode more than one column? how can I add the new columns such that the overlap doesn't happen (0's and 1's of one column with those of the other)
Hey all. Not sure if this is the right place to ask. I am going to be building a rest api in python. This api will be receiving json 'events' from around 1000 iot devices. These events will most likely be sent multiple times every minute (every 5 secs, etc). I am looking for advice on what I should keep in mind when building this.
I've never built something at this scale, so I am a bit confused about what technologies to use. My first thought would be to have a redis server to queue up the events that needs processing.
@HibritUsta Getting closer... Now let's see a traceback. That's the part that starts with Traceback (most recent call last): and ends with the error message.
We need the traceback to determine which function is crashing with TypeError: a bytes-like object is required, not 'str'. This will tell us which objects need to be turned into a bytes. It seems like you suspect that new_paket is the object that needs to be turned into a bytes, but the encoding without a string argument error suggests that it's already a bytes.
@HibritUsta please don't use so many empty lines, your messages are taking up way more space than everyone else.
>>> bytes("foo", "iso-8859-1")
b'foo'
>>> bytes(b"bar", "iso-8859-1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: encoding without a string argument
Here we see that it's possible to specify an encoding when calling bytes on the string "foo", but it is not possible when calling bytes on the bytes object b"bar"
@davidism I didn't know how to explain the problem.
it is the right place, but very broad
do you need real-time processing? can you drop messages? are we talking message in the range of B, kB, MB, ...? are you just storing data, do you need to process or even reply? and so on...
16:11
To be clear, I'm interested in the traceback belonging to TypeError: a bytes-like object is required, not 'str', rather than the one belonging to TypeError: encoding without a string argument. Ideally I'd like to see both, but the first one is far more important
@Kevin So what should I do for the right solution
@HibritUsta I can't give you any advice until you give me the traceback.
... And until I have lunch. rbrb
The data should be very small in size, a simple json dictionary. I only have to store the data that is received in a mssql database. The data will then be available through a different api (not a concern). I am mostly looking for pointers for how to handle the traffic.
scapy package [scapy.Raw] .load data type: byte
byte to str to the data type to be able to process.
@n0rd I assume with "REST API" you imply full HTTP, not just TCP or even UDP?
16:19
@MisterMiyagi Yup HTTP REST, my bad. So far I have been using aiohttp for my api's, but as mentioned its the first time im building something that has to handle this kind of traffic.
@MisterMiyagi But if there are downsides to HTTP I am free to go in another direction
aiohttp should do well, async event loops can manage a 10k-100k messages per second: github.com/MagicStack/uvloop
@HibritUsta, that doesn't look like a traceback to me. A traceback starts with "Traceback (most recent call last):".
it is just some useless overhead for sending raw JSON
but if you ever want to add proxies or security, its worth it
@MisterMiyagi Great ressource thanks! So on the surface I shouldnt need any supporting software? Like setting up a redis queue to handle the requests? I also want to ensure that data cant be lost (if possible) But this probably has mostly to due with my implementation correct?
"no data can be lost" is mostly a decision you have to make
16:26
Yup. My thought exactly
Thanks for the advice! I gtg, have a nice day all
from the way you describe your setup, there seems to be no harm in loosing a few messages
whenever it is acceptable to miss messages, I recommend exploiting that
16:37
@MisterMiyagi Had to get off the train, but just had a follow up. Lets say I had a million of these iot devices that each has to send, lets say 20kb every second. How would you personally go about something like this?
I suspect "ensure that data cant be lost" is one of those things that you can never 100% guarantee. There's a correlation between how much hardware and man-hours you can throw at the problem, and how many 9s you can put on your "99.999...% guaranteed" marketing blurb
at that scale, you want to have several servers for load balancing and high availability
that is actually going to make things easier, since you are prepared to scale out anyways
though putting it all on one box is still pretty feasible
Okay great. This has been very enlightening for me thanks a lot :)
from my experience, efficiency actually *improves* once you accept that some data is lost
it reduces overhead (thus improving throughput) and complexity (thus improving reliability)
Makes sense. There's a reason UDP is faster than TCP/IP :-)
TCP tells its packets "text me when you get there". UDP sparta-kicks its packets out of the nest and yells "fly, baby, fly!"
user10984358
16:55
if I have a dataframe 'df', will doing the following create a new data frame or just a reference?

newdf=df
user10984358
same goes with newdf=df[:]
newdf=df.copy() is better i think
user10984358
I was about to ask if there was pandas-ey way to do that, beat me to it
Assigning a variable to another variable never creates a new object.
@TheNamesAlc what Kevin said
it's fundamental python, pandas doesn't have a chance
user10984358
16:57
a='some string'
b=a
newdf = df[:] is probably also not a copy, and this is on pandas
user10984358
that works differently I presume
Nope, a and b are the same object.
it works the same
@TheNamesAlc the second one is up to pd.DataFrame.__getitem__
16:58
I almost never say "never" without putting "almost" before it, but I'm pretty confident about this one.
for python lists lst[:] creates a copy, for numpy arrays arr[:] creates a view (not a copy, but not the same object), and for pandas I don't know but probably the latter
user10984358
I added some words to b and it was not reflected in a, and vice versa
@Kevin how about *a, = *b,?
Keep in mind that a = a + "blah" does not modify the value of the string originally referred to by a
strings are immutable; they cannot be changed. If it looks like a string is changing, you're actually creating a new string that merely bears some resemblance to the old string.
16:59
@TheNamesAlc that's because strings are immutable. b += "foo" changes what b points to
00:00 - 17:0017:00 - 21:00

« first day (3181 days earlier)      last day (1992 days later) »