« first day (3156 days earlier)      last day (1783 days later) » 
01:00 - 17:0017:00 - 00:00

5:00 PM
and yeah, it's many-to-many on a lot of the stock e.g. washers or nuts, but that's irrelevant in listing a parts list for a single machine, which can be considered like a "master" starting point for the recursion. Once you select a machine, we don't care about what parts can be used elsewhere
 
We've got something like that in my work DB. Effectively, we have a separate table COMPONENTS just for describing the "x is made out of y" relation between parts, distinct from the PARTS table.
So if you had a death ray that was made out of a nut and a washer, the tables might look like
PARTS
id  name
0   nut
1   washer
2   death ray

COMPONENTS
part_id  component_id
2        0
2        1
This at least lets you efficiently find the direct components of a part. But you'd need more than one query if you wanted to find the components of those components, and the components of the components of the components, etc.
 
You can do multi-level with just MACHINE (top of the scale) and PARTS, provided that PARTS have a parent_id field
 
recbg
 
Then you recursively go down to parts-of-parts and parts-of-parts-of-parts just by parent_id
 
someone just asked me where should one learn numpy.
 
5:05 PM
cbg
 
Its making me realise i have no idea how i managed to finally pick it up.
 
SO probably
The numpy tag is not sullied like the Python tag. I think I probably picked it up by looking at answers and then following up on the method names used
 
it's such a broad topic, any tutorial that im trying to look at now is definitely too basic for my colleague at a glance
i was wondering if folks had any go-to or recommendations here, assuming one is proficient in python
yeah, i think it was basically just randomly stumbling into Divakar's answers on SO.
if i got his name right..
 
Pretty much what I said. Once you go through the official docs on indexing, just start following answers from people like MaxU, PiR, Divakar and the other main names
 
I'm learning numpy by hanging out in here and letting the wisdom diffuse into me
 
5:10 PM
yeah, i've seen Divakar answer just about every numpy question that i myself searched
 
I haven't seen much from MaxU for ages but his answers were more accessible than Divakar's
Divakar has an unusual brain; you know you've found the answer to your problem if one of his answers comes up in your search... the next part is understanding how the hell it works
 
haha, that's so relatable!
one of the first times i stumbled into one of his answers, i had to spend a couple hours before i understood what was going on completely.
this is maxU ?
 
Yep
 
fun fact: you can multiply a dataframe by a dictionary
df = pd.DataFrame(1, range(2), [*'xy'])
df * {'x': 2, 'y': 3}

#    x  y
# 0  2  3
# 1  2  3
 
But why
 
5:15 PM
^
 
broadcasting on steroids
 
FUN
 
 
Bold and italics guys. We better take the advice.
 
Also, I miss seeing MaxU around. He's super great
 
5:19 PM
@piRSquared reminds me of one of my friend's signs on their wall at uni; "the beatings will continue until morale improves"
 
lol
@Kevin but seriously. If I want to multiply each column by a different number, I can multiply by a list/array or a series/dict. Using the dict saves me the construction of a series and it also guarantees alignment of correct columns to numbers.
 
Who am I kidding, I've done way worse.
 
nothing like writing code to enable our inner madness
 
can anybody please answer this question:stackoverflow.com/questions/56498607/…
I would be very appciated
 
Doesn't work for me in pandas 0.20.
 
5:27 PM
@chiragsoni Please take a look at our room guidelines, we prefer users wait 48 hours before posting links to their unanswered questions.
 
You've defined a class Kibbles with __lmul__ and __mul__ and done Kibbles(A) * B The internals of of the class shuffle through various classes until it finds a compatible pair and performs *... amirite? @Kevin
 
Ok fine
 
im both surprised and placated at the same time that i cannot selectively multiply a dataframe with a dictionary that doesn't have all columns listed
 
@ParitoshSingh twice in less than 24 hours I've seen yet more wonky behaviour from pandas above my version. Be placated.
 
tell me about it
 
5:29 PM
tell me about it. (pun intended, but no, actually curious!)
 
exhibit 2 although this one is intended behavior, not a bug
 
^ closed
 
that was fast, thanks
 
5:36 PM
@roganjosh this one is so weird to find and deal with. i haven't really had to use .isin all that much, is the general advice to then avoid it whenever possible?
 
Today I am annoyed by inspirational messages that are worded like "don't worry if you haven't achieved all your life's goals at 21. Heck, even if you're 22 or 24 or even 29, you're doing fine!"
 
@ParitoshSingh I'm not an authority for "general advice" on something like this, but I certainly won't stop using it. For my version, it works how I expect it to work
 
@Kevin it's never to learn to achieve something?
 
Their mouth says "there's no deadline" but their heart says "the deadline is 30"
 
well some things do have a deadline, based on how biology/human body works
 
5:39 PM
@ParitoshSingh The only thing recently that I've seen that I would like is a mixed column of nan and int. I'll forego such things for the sake of not updating, but it's always going to be case dependent on what you need pandas for, I guess
 
Quite a lot of things have a deadline and it is when you die
 
aye. is it just dependencies that are making you not update or something more than that?
 
@cs95 did you see my link on the dup you hammered? I asked that 5 years ago stackoverflow.com/q/25435229/2336654 (-:
 
@ParitoshSingh the pandas API and its internal behaviour being screwed with
 
@Kevin bravo! you got it :), hence the "dead" in deadline :)
 
5:42 PM
Actually, that portion surprises and confuses me. I hadn't known about pandas 2.0 till it was linked in chat a couple weeks back. yet pandas 0.24 or whatnot forges on, and are making major api revisions in a setup where apparently it's already tough to make things consistent.
 
I don't think I have anything that requires a version higher than I already have, and at least basic things like isin behave as I expect... presumably because I've had this version for a while
 
I've always been wary of pandas because i've found a lot of its behaviours fairly "quirky" to say the least
 
In the pandas 2.0 discussion, I also said I think it is dead
It all seems to have dropped off in terms of blogs etc and the public repository hasn't really been touched
 
Pandas is amazing and can make a gazillion tasks easier. Its people stretching it that tarnishes its good name.
 
@ParitoshSingh the real pandas are quirky too, I saw quite a few of them when I went to Shanghai :)
 
5:45 PM
@piRSquared this i can sorta get. whenever you're dealing with tables, pandas is the defacto go-to. at the same time, i dont put the blame on just users though.
say, for example, i looked at pd.DataFrame arguments a couple times
iirc, there's 3 separate arguments for separators
 
Well, it would also depend on what docs you're looking at, because I've found several that have fallen out of sync with the actual library
 
That's just the absolutely most basic call you can have while making a dataframe, and the first thing you're greeted with is a hodge podge of so many arguments it's hard to take them all in.
@DeveshKumarSingh ha, never seen a real panda up close. they look cute on telly :P
@roganjosh hm, well, i didn't turn to docs when doing this, spyder kinda just plops the function's docstring in a separate tab.
 
Wait. This is what I get for DataFrame's signature
pd.DataFrame()

Init signature: pd.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
 
@ParitoshSingh The docs are created from the same material, I think. Maybe Sphinx like numpy
 
oh! oh wow, that's so much cleaner haha
I suppose i shouldn't forget it's a work in progress.
 
5:50 PM
@ParitoshSingh telly? isn't that the british word for television?
 
it is
 
aye ^^
 
Though I'd say it's falling out of use considering we have "HDTV" etc. on adverts, so people are more likely to say "T.V." these days
 
aah okay, even I say that word out loud in an accent :) heard that in the British verison of The Office I think
 
@piRSquared huh!
 
5:55 PM
I'm not sure that I see that as too broad
 
Yep, realized as soon as I posted
 
Plenty of discussion like that happens in this room; people even make challenges from that kinda thing
 
I can replicate OP's behavior in a REPL, for what it's worth
 
yes, i can too in a REPL, but not in an IDE
 
I suspect that is also true for the OP. I wag my finger at him for not specifying to begin with.
 
5:59 PM
now how do we import it back?
even the import statement stopped working
 
I'm skimming through nedbatchelder.com/blog/201206/eval_really_is_dangerous.html to see if there's a way to access anything useful just by using objects we can create from literals
 
wim
@Aran-Fey switch to java
 
[].__class__.__bases__[0].__subclasses__() turns up a whole bunch of stuff but I don't immediately see anything useful
 
I think we had a series of "break/unbreak python" tips here a while back
 
I found what I needed at the bottom of the article :-)
Hmm, OP claims that his behavior occurs even when running a proper script. I am befuddled.
 
6:08 PM
@Kevin clearly an antipattern to take the zeroth element of a list comp!
 
I guess I could use next...
Or, wait, I can't, because it's a builtin
 
wim
oh, that was a fun puzzle, restoring the import system.
 
(If it's not clear from context, all the builtins have disappeared. Context: stackoverflow.com/q/56499060/953482)
 
@Kevin aaah!
 
@Kevin how did u even reach that article!
 
6:11 PM
it's a well-known source (presumably from there)
 
I guess I could do (generator).__next__(), but manually calling dunders is about as wtfy as [0]ing a list comp, so meh
 
@AndrasDeak do you mean ned's blog?
 
@Kevin yeah, I agree
@DeveshKumarSingh that and also the post itself chat.stackoverflow.com/…
 
I reached that article by storing its title in my long term memory after seeing it posted in here a dozen times over the years. It's a fun read.
 
ohh okay :) seems a bit advanced on first look, guess I need to better understand the import system to grasp it
 
6:16 PM
I deffo do not understand half of the code blocks on the page. No matter, I'm still sufficiently awed by the demonstrated difficulty of building an inescapable sandbox.
 
Trying to inspect the code that I submitted... Why does the warnings module have a __builtins__ attribute? Is that typical for modules?
Trying other modules at random, I see that timeit has the same attribute, but math doesn't.
Maybe it depends on whether it was defined in C
I guess it makes sense if all top-level contexts automatically get a __builtins__ name in their highest scope.
 
wim
6:36 PM
uff, OP accepted the dodgy answer
 
;_;
I feel like some formulation of this challenge should be added to the riddles page
 
I think the answerer used what OP wanted to use in the first place
 
wim
@Kevin I think it's normal for .py modules
math is probably a module from compiled code
(check math.__file__ to be sure)
you could probably use any other .py module which is imported at python startup in place of warnings (e.g. io module)
 
I've added the three-part builtins deletion challenge to the Riddles page. It is somewhat incomplete since I am a dullard and can't provide commentary on the solutions for the first two, or provide the solution for the third one.
 
wim
6:51 PM
Aran-Fey did solved the third one too though
 
Oh, maybe I didn't scroll down far enough. Let's see...
Yep, there it is.
@wim Yes, I agree. I guess warnings was just the easiest module to access, or just the first module that they tried that worked.
I don't think you can easily get a module reference from any old object. ._module isn't a native part of the object model -- catch_warnings goes out of its way to assign it during initialization.
So you could access other modules this way, iff you can find an object that has explicitly kept a reference to the module.
 
wim
Sep 12 '18 at 16:55, by wim
>>> class CM:
...     def __enter__(self):
...         return self
...     def __exit__(self, *args):
...         print('hello world')
...
>>> with CM() as cm:
...     ...
...     # your code
...
goodbye world
maybe add this guess the output one too
May 20 at 19:45, by wim
>>> x, y = x[y] = {}, 0
>>> x
<you guess the output>
 
Aye, I may as well, since I'm about to add this puzzle:
Guess the output of these two programs:
#PART 1
x = 0
def f():
    x = 1
    class A:
        x = 2
        class B:
            print(x)

f()

#PART 2
x = 0
def f():
    x = 1
    class A:
        x = 2
        class B:
            print(x)
            x = 3
f()
 
@wim ah, the first one I understood I think
he said "guess", not "run and report"...
 
7:06 PM
hence removed the comment
 
wim
heck, sorry
 
qq
it's burned into my retinas
 
wim
hah
fix the damn spoiler feature already
 
Half of the reason I want to curate riddles on a page separate from chat is so it doesn't matter if users get excited and quickly give out the answer.
 
wim
I have an easy puzzle but only works in 2.7
create x, y, z such that
>>> x < y < z < x
True
only literals are allowed
(I don't actually know if there is any possible solution in Python 3, but I strongly doubt it)
 
7:16 PM
wow, this one looks absolutely wicked
 
wim
similar puzzles that do work in python 3 too:
- create dict instances x,y,z such that `x == y` and `y == z` but not `x == z`
- create datetime instances x,y,z such that `x == y` and `y == z` but not `x == z`
 
normal dicts work?
 
^ closed
 
thanks
 
wim
7:28 PM
@ParitoshSingh in 2.7 it is possible with normal dicts. in 3.x the 2.7 trick no longer works, but it's still possible using dict subclass from collections... (big hint)
 
oh!
yeap, i think i got it with that hint
let me test
yep. got it. spoiler
 
nothing seems to show up on hovering, on clicking it links back to the room
 
oh well :)
 
I can see the alt text when I hover.
Moderately stymied by x < y < z < x because I can't remember how view spoiler works in 2.7. The documentation basically says it's implementation-dependent.
 
doesn't it spoiler?
 
7:38 PM
I thought the CPython approach was view spoiler but that doesn't explain why view spoiler
@AndrasDeak Uhh. Maybe? It's consistent with my otherwise-confusing test results.
Perhaps I can work with this...
 
Never been happier to see an error TypeError: '<' not supported between instances of 'dict' and 'tuple'
 
Hmm, Andras' idea seems to be disproved by view spoiler Unless there are extra rules for x's type there
(On my machine this prints True and then False, if this happens to be environment-specific behavior)
 
both are False for me
10 points for documentation speaking the truth ;)
 
Which rather torpedoes my idea.
 
@ParitoshSingh @DeveshKumarSingh Room 6 unite. One more comment from regulars here and we'll have Captain Planet summoned
 
7:49 PM
hehe
 
@roganjosh I didn't understand what you tried to say, who's captain planet?
 
@Kevin docs.python.org/2/reference/expressions.html#comparisons (nevermind, this is where you started from)
 
Earth! Fire! Wind! Water! Heart! (wub wub wub wub)
 
@roganjosh I know the series, I thought we had a captain planet of the room
 
7:51 PM
guy knew the importance of managing pollution even back then, bless his heart
 
@AndrasDeak Yeah, that's what I was looking at. "The default order comparison (<, >, <=, and >=) gives a consistent but arbitrary order." is what I was complaining about being too vague.
 
Yeah, sorry, realized too late.
 
No, I tried humour but you've slapped that one down :P
 
@roganjosh aah, you meant 1 more user to add to the 4 already commenting here ?
 
Yes, I was commentating on room regulars piling on to the same problem
 
7:54 PM
 
@roganjosh Wow, I can understand the lyrics of the theme song. Definitely couldn't last time I heard it.
 
@roganjosh okay, that's pretty deep but I got it finally :)
 
@AndrasDeak was it ever on Cartoon Network? You must have scoured further than CN when you were a kid
 
no, it was only CN here, and yeah, it was there
 
we used to see this in my mother tonuge (Hindi) The theme songs sounds and means way funnier
 
7:56 PM
It's a lesser miracle we had CN; the Eastern Bloc wasn't famous for foreign-language broadcast and my parents never paid for any extra channels anywhere. Whatever came through the plugs.
 
Captain Planet is also in Hindi??
Wow, I didn't think it was that big :P
 
just about every cartoon had dubbed versions for india back in the day, english channels for cartoons was uncommon to say the least.
 
Cartoon Network is making a comeback with some decent shows these days
they were airing utter crap in the '00s and early '10s
 
yes, I used to watch dexter's laboratories and powerpuff girls in hindi
 
I've got all of dexter's lab and 2 stupid dogs and courage the cowardly dog downloaded
 
7:59 PM
Did you have Pinky and The Brain?
 
gumball and adventure time stream on hulu. Following
 
I also remember watching catdog and swat kats
 
@roganjosh yup, though I never liked the Animaniacs angle that much
 
I used to really enjoy it. I like how cartoons can get in innocent references for the adults forced to watch kids programs these days. Spongebob is not boring
 
well the fun is to actually understand the insider joke when you watch it as an adult vs you watching it as a kid
 
8:04 PM
I think Pinky and The Brain did some of the leg work in making it a norm
 
that or animaniacs, whichever came first
 
probably animaniacs
 
wim
@Kevin golf clap
now try the dict one
it's a lot easier than the datetime one
one of the answerers up there did also discuss the "Numeric types are ordered before all other types in CPython" thing too.
 
8:30 PM
I am practicing file sizes, however, this question is a little tough as I am unsure of what "K" is the abbreviation of. Is "K" another abbreviation of KB (kilobytes)? Or what is K the abbreviation of in this context?

*"Kevin is entering the JS1K contest, a contest to write an interesting program in just 1K of JavaScript code. He's hoping he can rewrite a program that's currently 1MB and enter that for the contest.

**If he succeeds, how much smaller will his new program be?**"*
 
wim
for js1k, it's 1024 bytes
 
So, "K" is indeed a synonym for "KB" (kilobytes)?
1024bytes = 1 KB
 
wim
not always, but for that contest it is.
 
kilo vs kibi, 1000 vs 1024
 
wim
if today's Python quiz were too difficult, you're invited to try this easy puzzle
 
8:35 PM
power-of-ten (SI) vs power-of-two
 
Huh, okay, I haven't learned about that base thingy..
 
Ah, I see!
 
personally, I think this power-of-10 standardization is silly and only leads to confusion (and of course sellers will always use the base that gives you larger numbers)
 
Haha, there is even a "yottabit", these names though
 
8:38 PM
those are standard SI prefixes
@wim better late than never: spoiler
oh, that was quite overengineered
 
8:54 PM
cbg
 
Straw poll: implementing class equality purely for testing purposes, y/n?
 
please define class equality? I have heard of instance equality
 
@DeveshKumarSingh Instance equality is what I think I'm referring to. Presently with no use in business logic, but might be better than using the my_class.json_dict method for comparisons.
Which is what I'm using right now, and is fine, but not as elegant as ==
 
adding an __eq__ doesn't really add complexity to the class, so even if it isn't used in the codebase itself I'd think it's ok
if it helps to make tests look more straight forward, even better
 
@toonarmycaptain you mean this?
class A:
    def __init__(self, a,b):
        self.a = a
        self.b = b

    def __eq__(self, other):
        return self.a == other.a and self.b == other.b

print(A(1,2) == A(1,2))
print(A(1,2) == A(2,1))
 
9:02 PM
@DeveshKumarSingh Yeah.
 
yes why not, perhaps you can write __eq__ more succicntly by iterating over all attributes in a for loop
 
I mean, I thought to use the same method under the hood (in this case a method which transforms the data to a json-compatible dict, or json string) at least until there's a business case for implementing it differently. I haven't written a non-toy __eq__ method before.
 
you lost me
class A:
  ...
  def json_dict(self):
    # not used in prod code ... yet
    ...
  def __eq__(self, other):
    # only used in tests, ever
    return self.json_dict() == other.json_dict()
@toonarmycaptain is this what you're doing?
 
9:19 PM
@Arne for the equality method, yes, the json_dict method is used in production, equality isn't.
 
ah, then i stand by my vote
 
Cheers :)
 
wim
@AndrasDeak works
 
alas, it's a needlessly complicated version of Aran's solution
 
wim
yes
 
9:28 PM
and anyway I wouldn't have guessed the actual solution part without the "distinguish a lambda" problem from earlier
 
wim
@toonarmycaptain n
unless you are modelling an immutable type and can define a sane __hash__ aswell, then maybe.
 
@wim what if I use a json str?
 
wim
they still shouldn't be equal. you can take attributes on, that go in the instance __dict__, and such details should not be invisible to any reasonable notion of equality
otherwise it makes your objects behave weird when placed into sets/dicts (py2) or prevents you from putting them in sets/dicts (py3)
if it's an immutable type, you have __slots__, and you can sensibly define __hash__, then its defensible. but just for testing purposes, no, keep the code which is only for test in the test code
for example registering a custom assert in pytest, or just define your own compare_myobj(one, two) helper function in the test code
 
9:48 PM
@wim why is it a bad idea to write a class with an eq but not a hash?
 
wim
9:59 PM
it can do weird stuff like this
>>> class A(object):
...     def __init__(self, var):
...         self.var = var
...     def __eq__(self, other):
...         if not isinstance(other, A):
...             return NotImplemented
...         return self.var == other.var
...
>>> a1 = A(1)
>>> a1_ = A(1)
>>> a1 == a1_
True
>>> a1 in [a1_]
True
>>> a1 in {a1_}
False
 
is that pythoff?
 
wim
yeah
in py3 they "fixed" it by kicking out __hash__ if you define __eq__
 
genious =D
 
wim
This somewhat non-obviously means that defining an __eq__ has the side-effect that you can't use instances of those objs in a lookup dict. It's not a fair price to pay if you only added the eq method for a testing convenience, IMO.
 
funny that I never heard about this py2 -> py3 change, it must have broken a bunch of code
@toonarmycaptain I retract my vote ^^
 
10:31 PM
What's this about votes?
 
🤔
I abstain
 
@toonarmycaptain seems ok to me
 
I reason (and have for a long time and told everyone else to do so as well because I'm opinionated) that since you need __repr__ for decent debugability and reasonable output on the REPL, and since a good (if trivial) __repr__ should have instance == eval(repr(instance)), and you should want decent coverage, then you should implement a __eq__.
 
Meaning that you should have a test for __repr__ that asserts that property?
 
10:41 PM
Yes, if reasonable to do so.
Sometimes state can't be captured in a __repr__, but much of the time it can.
I have an answer and have given a talk where I have asserted as much.
 
hmm, somehow I PlaidML appears only installable in a virtualenv. Trying to install outside of a virtualenv causes piadml-setup to fail with a very generic error message. In addition trying to build from source also fails because 1: There is an incorrect version of llvm listed, and 2. llvm can't find histedit.h (even though I have libedit-dev installed. -_- installation is such a pain sometimes.
 
Permission issues perhaps? Anyway having to use virtualenvs is not that bad
 
yeah, the virutalenvs aren't too bad, but I really want the source to build lol.
i'm gonna try sudo tho. we'll see haha. Thx.
this is gonna take a while :P
 
I'd start by trying to decypher the "very generic error message" but you do you :P
 
@AndrasDeak The cryptic error message was fixed by using a virtualenv and is mentioned in a thread on their repo
 
10:52 PM
OK
 
basically, they have yet to implement the full error and it is a bunch of shudders C++ code...
but lol i was looking through their Keras implementation and they use builtins.abs from six. I'm like 99% sure that is a mistake.
 
No, it checks out. abs <-> six-pack
 
CPU > GPU confirmed.
it is interesting though that somehow it only works with virtualenv...
I can't believe I over looked sudo, that's like the first thing I should try when an install doesn't work lmao.
 
I'd have tried installing with --user before sudo, though
 
I prefer a more dangerous life to keep installation exciting. :P (Totally not because I didn't know --user was a thing)
 
11:26 PM
fingers crossed but sudo appears to be getting further than without...
nope lol same error about histedit :/ Thanks for the help anyways.
 
01:00 - 17:0017:00 - 00:00

« first day (3156 days earlier)      last day (1783 days later) »