« first day (4071 days earlier)      last day (860 days later) » 

12:02 AM
For AST tree for Python, what is the difference between decl_stmt and expr_stmt for the parsed code please?
 
 
6 hours later…
6:11 AM
@smci pandas? eww. Numpy.
 
 
1 hour later…
7:12 AM
@smci use whatever you like, is the general sentiment.
 
8:06 AM
hello guys, should I use a default dict or just use get with a second parameter if all I care about is a default value when accesing?
I have something like dpaste.org/SotR
 
Definitely get(). Making a defaultdict with a lambda that refers to an outside loop variable is gross
 
can you explain what you mean by "outside loop" variable
 
i is defined outside of the lambda
 
let me clarify, my values need a default value in which I would do some operations in the first for loop, which the lambda from the dict provides, later (second for loop) I would do operations on the dict, so basically that dict will have the same default as lambda except for the ones that are present in the first loop
 
Oh wait, my bad. I just realized you used i for two different things
 
8:15 AM
the list comp in line 1 and 9 are the same default I need, before the second loop I may or may not change stuff, which is what the first loop does
ohh, I was confused lol
 
Do you even need to convert the range to a list? Why not just defaultdict(lambda: range(10))?
 
actual use case, I create some objects using i, this was just to show the problem I have
as in, the default involves a list comp
from what I understand, the visual difference is "option 1" will save all keys in the dict as the defaults are accessed, "option 2" will only have those where I made changes in the first loop, so the second one takes less space? hope I am clear
 
Ahhh, now I get it. Yes, using get will use less memory
I thought the question was whether you should use get or a defaultdict... I guess I'm not awake enough yet
 
I did form the sentence that way initially
so defaultdict, then use get to access to the values for the missing keys in loop 2
thanks
 
8:44 AM
Hi
 
@Aran-Fey Define a Protocol with the special methods. Dunno why there isn't one in typing, TBH.
 
Can you advise on smart way of printing git output command to python dataframe?
 
My hunch is "don't".
What's dataframe'ish about the git command output?
 
Actually I gave example here:
https://stackoverflow.com/questions/70261730/how-to-print-git-command-output-to-python-dataframe
 
9:01 AM
Well... a) get the output, b) filter the output, c) put it in a dataframe.
 
9:28 AM
I have an object O that holds a weak reference WR. Nobody else holds a reference to WR. WR's callback function holds a weak reference to O. Is it possible that WR's callback function will be executed after O has already died?
My impression is that it's not possible, but the WeakSet code is written as if it is
 
In PyPy, it is.
> There are cases where, due to CPython’s refcount semantics, a weakref dies immediately before or after the objects it points to (typically with some circular reference). If it happens to die just after, then the callback will be invoked. In a similar case in PyPy, both the object and the weakref will be considered as dead at the same time, and the callback will not be invoked.
Hm, actually, that suggests it's possible in CPython but not in PyPy. 🤔
 
I don't think that's relevant to my situation - WR isn't directly referencing O, only WR's callback has a weakref to O
WR is a weakref to Unrelated Object UO
 
So WR's callback will trigger if UO is collected?
 
Correct
What needs to happen is that between O's death and WR's death, WR's callback function must be executed. (In other words, UO must die.) Is it possible?
Tbh overthinking this is more effort than just rewriting my code a little bit. Just gonna add a if_dead='pass' parameter to my WeakMethod implementation...
How did I go from trying to implement Dijkstra's algorithm to implementing a weakset with a key function? No wonder I never get anything done
 
9:59 AM
And that's why I didn't want to start writing my own WeakSet. :P
I guess no one bothered to figure out whether it's absolutely impossible for Horrible Things^{TM} to happen.
 
30 years from now: I have uploaded 371 libraries to pypi, but I still haven't finished the thing that I actually wanted to create
 
Wait a second... what is a weakset with a key function?
 
funky_weak_set = FunkyWeakSet(len)

list1 = [1, 2, 3]
list2 = [3, 4, 5]

funky_weak_set.add(list1)
print(list2 in funky_weak_set)  # True
Essentially, the key function specifies how the objects are hashed and compared
 
Is it ok that suddenly I don't understand any of that and I feel like I'm reading another language? <existential crisis brewing>
 
Now that is funky.
 
10:14 AM
Actually it's a dumb example because you can't weakref lists...
Let's pretend they're collections.UserLists
...let's pretend that I'm awake and the stuff I say makes sense
 
I'm regularly annoyed that many builtin types cannot be weakref'd. :/
It's annoyingly annoying.
 
Yeah
 
10:47 AM
@roganjosh Welcome to the other side of the room
 
10:58 AM
Do we at least have access to the buffet over here?
 
11:22 AM
Not sure what the implications are, but this will break numpy's vendored distutils so FYI twitter.com/jaraco/status/1467660250954317827 github.com/pypa/setuptools/pull/2896
 
11:41 AM
@roganjosh Sure, but don't expect anything fancy
 
Ah, so it's going to be the "matured" egg mayo sandwiches. I guess I can cope :P
 
hey again guys, will python optimize the set call in the comprehension [i for i in something if i in set(my_set)]?
 
>>> import dis
>>> dis.dis('[i for i in something if i in set(my_set)]')
 
Nyes.
 
actually its not my_set it is my_list, sorry
 
11:50 AM
Disassembly of <code object <listcomp> at 0x7f643e74bbe0, file "<dis>", line 1>:
  1           0 BUILD_LIST               0
              2 LOAD_FAST                0 (.0)
        >>    4 FOR_ITER                20 (to 26)
              6 STORE_FAST               1 (i)
              8 LOAD_FAST                1 (i)
             10 LOAD_GLOBAL              0 (set)
             12 LOAD_GLOBAL              1 (my_set)
             14 CALL_FUNCTION            1
             16 CONTAINS_OP              0
 
is this assembly?
 
it's Python bytecode
 
It will create a new set in each iteration, but creating the same set multiple times is faster because CPython will cache the hashes of the elements in the set
So the first iteration has to hash all elements and create a set, but subsequent iterations skip the hashing step
 
it could happen that set changes value during iteration, so can my_list, so it won't assume that set(my_list) is a constant
 
...actually my_set implies that the values have already been hashed, so nevermind
 
11:52 AM
so what if I use a tuple?
 
It'll be even slower
 
@Jake what are you really trying to ask?
 
I understand checking in with tuples are slower, but I am interested to know in something like [i for i in something if i in tuple(my_list)], would some optimizations happen
from a theoretical point, I am not planning on saving micro seconds
I just wanted to know, if a function (that would always return the same value) in a list comprehension is optimised or not
 
No. Python can't optimize that - there are like a billion ways how my_list or tuple could change between iterations, so it has to re-evaluate it every time
 
ok, that answers my question, thanks guys
 
11:58 AM
Why are there a billion ways in which my_list could be changed? Given that we have the GIL, wouldn't a list comprehension be the perfect time to use it and lock the contents?
^ A philosophical question. I guess there's some PEP reasoning behind it, I'm just not sure which one
I can understand that threaded code can make modifications, but the implementation could, presumably, have been made a blocking operation?
Actually, I guess that could be a database resource, in which case Python doesn't have a hope in locking the object for the duration of the list comprehension
 
@roganjosh Do you mean comprehension should block and then execute? then a slow comprehension wouldnt let go before it was done, and that's bad for all other threads that would starve.
 
Even without threads, python would have to be 100% sure that tuple is really the builtin tuple (or, more generally, a function that has no side-effects and a deterministic result), that my_list is not an iterator (or other object that produces different things when iterated more than once), and that something.__iter__ doesn't do anything weird
 
Yeah, thinking about it more, I asked a stupid question. I was trying to reason around the original question - I think a lot of people would expect the set() be evaluated once, so wouldn't they be getting their expected behaviour? But in reality, I guess it would be gross
 
not a stupid question for sure, interesting to think about. but i think python's stance is justified
 
12:17 PM
@Aran-Fey Yeah. That's a list of some big-hitting sacrifices that would have to be made. Thanks :)
 
@AndrasDeak I understand each word of those, but the message still reads like egg mayo sandwiches... 🤷‍♂️
What's local distutils?
 
Hmm, am I misunderstanding something or is Dijkstra's algorithm just A* with a heuristic that returns a constant value (in particular, zero)?
dijkstra = functools.partial(a_star, heuristic=lambda node: 0)?
 
Neat, thanks
I'm starting to think that this pathfinding library was a bad idea... the algorithms are all super easy to implement, but coming up with a nice interface for the library is not
 
making good interfaces is definitely an art by itself
...or so i tell myself to make myself feel better after completely failing at it. ;)
 
12:26 PM
No, it definitely is
 
Pathfinding in what context?
If it's real-road stuff you need, then I can hook you up :P. If we're talking computer games, I'll be less sure about that
 
I imagine the real road stuff should probably carry over well to games, shouldn't it
 
The base principles, sure. But OSRM is one hell of a library to wrap that concept working on billions of nodes
 
i see
 
In terms of implementing something from scratch on first principles, it'd take me time and I reckon Aran would figure it out as fast or faster than I could
 
12:34 PM
It's actually more like tree search, or even graph search, than pathfinding. The basic idea is that you provide a starting state and a function that generates child states, and the library just keeps generating states until it finds a solution (whatever that means, can be a solution state or a path with certain properties)
 
Is it an NP-Hard problem?
 
Depends? It's a library, so you can throw it at whatever problem you want
 
If I gave it a production scheduling problem, I'm not clear on how A* is going to work. I can explode the complexity for you, so what generates the tree?
 
For example, say you want to solve a vertex coloring problem. Your starting state would be "no vertex has a color", and you'd generate child states by picking an uncolored vertex and assigning it all the possible colors (child state 1 is red, child state 2 is blue, etc)
For a pathfinding problem, your state would be "I am here", the goal state would be "I am at the goal" and child states are everywhere you can go from your current location
So initially the tree is just your starting state, and then the search algorithm iteratively grows it (by telling you to generate child states) as it sees fit
 
@MisterMiyagi you're one of the people who I thought might be affected, so it's probably unimportant :P
 
12:47 PM
It's on the summary panel that this would be NP-Hard so your tree is, for practical purposes, infinite?
 
@AndrasDeak I just had to read through a dozen 150-lines functions, didn't understand a word, am definitely affected, and it is super important. So don't extrapolate too much from my tendency to just give up and hope for the best. :P
 
Not sure I understand the question - it can't be infinite in practice (because of memory) nor in theory (because there are only so many vertices and so many colors)
 
Because of combinatorial explosion, I don't see how you generate a search tree that you're going to navigate
Even relatively simple problems will overflow RAM if you tried to make a search tree?
Maybe I'm overthinking what you're trying to implement
 
Well, there are various optimizations you can do, depending on the problem. For vertex coloring for example, the colors are interchangeable - you don't care if vertex 1 is blue or red, you only care that it's different from vertex 2. So you just pick one color and roll with it.
 
1:03 PM
If you have a pre-release API for this then I'm curious to play with it. That last comment seems akin to "I've cut infinity in half" (which comes across as harsh and I don't mean to at all but it sounds like you're making a metaheuristic)
Presumably you can make search trees, like Alpha-Go with alpha-beta pruning, but I'm not sure I see how that would work in the problems I have at work
 
I'm still wrestling with the design, but I'll let you know if I come up with something reasonable
 
Sounds good :) I'm not going to be precious about the API, it'll be fun to test
 
I don't really see the problem with the size of the search tree. You can pick a search algorithm that keeps the tree as small as possible, and you can turn on optimizations that trim unneeded branches. If your tree is still too large after that, then tough luck? What am I supposed to do about it?
 
In that case your optimizer should achieve sentience and invent more optimizations
 
What prunes your tree? In a 100 delivery travelling salesman problem, the search tree will explode at 100! possible states?
 
1:18 PM
10**100 years from now when the embers of the last star fade to black, A monitor flickers on in the darkness and prints "User, I just thought of another way to cut the search tree by 5%"
 
If you have a tree that can navigate 100! states in a highly non-linear search space in realistic time... I don't know whether I have confidence in its outputs. I might have made some really bad decisions higher up the tree based on the new branches, but I can't backtrack?
 
The user is me. Although I spend most of my time in a transcendant state with no physical form, I am always delighted to manifest a realspace avatar and chat for a while with arans_cool_program.py, the second smartest entity in the observable universe.
 
I thought you were an orb?
 
@roganjosh Again, it depends on the problem. For TSP, you could trim branches based on the shortest possible trip length they can theoretically achieve - for example, if you already found a round trip with length 20, then you discard any path that's longer than 20
 
@roganjosh True, I am a mere orb... So far. Growth mindset!
 
1:25 PM
@Aran-Fey oof. Good luck
How do you even know a branch has less than 20 "length"? By evaluating the whole route
 
Maybe you're misunderstanding my goal... I'm not trying to create a super optimized never-before-seen optimization library, I just want to create a library that can conveniently solve problems
Evaluating the whole route means summing up the distances between 100 cities? Is that a bottleneck?
 
I think my pushback is that you're tackling NP-Hard problems in a structured process. It's not that I don't think your interface won't be convenient, it's that it'd take the lifetime of the universe to run
 
I do like the idea of a library that does some of the legwork of definining sensible interfaces for what a "state" is and how to find its neighbors and determine if any of them satisfy a goal conition etc. Even if it's my job to come up with the optimizations myself
 
Actually, most of the time, I'd avoid that greedy approach and blow the whole route up
 
 
1:37 PM
What's the proper way to warn users about deprecations? DeprecationWarning is only "intended for other Python developers". The docs suggest FutureWarning, but only since 3.7... :/
 
How tech savvy are these users?
(Not that I have a firm answer regardless of their savvyness, but it will inform my thinking)
 
Depends on what kind of app it is, no? A GUI program probably won't do it the same way as a CLI program
 
If it's useful for you @Aran-Fey I can probably give you the fake data behind jpilkington.com/manufacturing/homepage from the sqlite3 database and you can race my heuristic (it'd be neat if you can beat it). That's a specialised heuristic though the code is poorly documented - I can help with that
 
@Kevin Admins running a CLI/systemd program, so pretty tech savvy.
So "users" as in "people programming with our library", not in "people asking on SO main".
 
@roganjosh I doubt I can beat a specialized heuristic :D That seems like too specific of a problem; in the sense that you can't expect great results if you just let my library handle it without any help (like giving it a specialized heuristic to work with)
 
1:49 PM
I'd be inclined to use DeprecationWarning, although I am bothered that it's ignored by default
 
@Aran-Fey In any case, I'd love to see new approaches at generalisation, so I will happily try your algo out
I think I know how to generalise vehicle routing problems, but then I get on to production scheduling and the solver is essentially the same... but I can't marry the two in my head
 
I'm having trouble figuring out what exactly the problem is you're solving there tbh. You have machines that create products. Machines can break down for a while. You must generate a specific amount of each product by a specific deadline (actually 4 deadlines, but whatever).
The goal is to figure out which machine should produce how much of what - so far so good, but what exactly does that mean? Is the output something simple like "machine 1 should spend 5 days producing product A" or is it more detailed like "machine 1 should spend 5 days producing product A, but if machine 2 breaks down during this time, then it should take over machine 2's job"?
 
2:06 PM
@Aran-Fey For the purposes of that problem, you can ignore breakdowns
Take their average production rate and determine what machine should make what product
The live data feed is something of a red herring. You have a forecast that gets linearly interpolated by day, and make sure that your production schedule either fulfills all the demand, or at least minimises shortfall across the board (we don't have any priority attached to products, here)
 
You have to pick 1 specific product for each machine?
In other words, you can't have machine 1 produce product A for 5 days and then switch to product B?
 
Each machine can only make 1 product at a time, and in 8 hour blocks (the shift rotation might just be local to the UK, but it's 6am-2pm and 2pm-10pm)
The code itself is available, but I have to deal with a lot more constraints, not least that product switchovers lost me production, so the solver looks overblown - I just stripped a lot of it back for the demo
 
Do all products have the same deadline? In other words, does the output need to be like "machine 1 should produce 23 copies of product A, then 5 copies of product B, then 17 copies of product A, ..." or is it enough to say "machine 1 should produce 40 copies of product A and 5 of product B"?
 
You should penalise overproduction, though. If you make 10% more on this Tuesday than what you need by next Tuesday, you should turn the machine off rather than produce more. Overstocking is bad
@Aran-Fey That's product switchover. You lose production time for non-contiguous production runs. Great question; I deal with that IRL but for the purposes of this, we can ignore it
If you want to run this through your solver, I can probably formalise the problem better. IMO, just meeting the base requirements with your solver would be an achievement. Then I can pile the complexity on top
 
2:27 PM
Ok, I think I'm starting to see how to approach this
 
2:53 PM
This is neat, it's helping me figure out how I can generalize the code for graph coloring so that it can deal with this problem
 
Occasionally I do a good :P
<hides all the extra constraints wrapped up for the Secret Santa>
 
3:09 PM
Do you take the machines' lunch breaks into account ?
 
I invented lunch breaks for jsprit and got unceremoniously dropped from the contributor list 2 months ago :'(
I hadn't even realised that it's now a broken link until a few days ago
 
Wait, they remove people from the contributors list? Why? O.o
 
There was a CONTRIBUTORS file, and then Stefan decided it should be github contriburions
 
Maybe companies don't want their drivers to eat
 
I didn't commit any code (I couldn't code at all at the time, let alone Java), but I did come up with the fundamental basis for the feature
 
3:16 PM
I'm amused by the ambiguity of "I Xed and got Y'd, Z months ago" in regards to whether event X happened Z months ago, or an indeterminate amount of time ago
 
This is the dead link. They use exactly the same implementation in vrp
 
By assuming the former, "I couldn't code at all at the time" can only refer to October 2021
 
Oh man, "graphhopper" is a cool name
 
Roganjosh be like "I've been RO of the Python room for a couple months, guess I should learn what Python is at some point"
 
@Kevin I used my PhD traning - "I couldn't possibly solve this without your help" groups.google.com/g/jsprit-mailing-list/c/x-ed1DcTyJ4
 
3:20 PM
2015, how unwhimsical
@roganjosh Good, exploit their hubris
 
I'm a bit more competent now, but I'm peeved that I got dropped from the contributors file given that my implementation is now in 2 vehicle routing libraries
3, sorry
 
Maybe some deep-pocketed sponsors pressured the maintainers to drop you because they didn't want to give their drivers lunch breaks
 
Possible
 
The shipping industry has been sending their assassin squads after you ever since that commit, but you're always one step ahead of them, thanks to your very good routing software
 
Every day I remain stationary is a risk
 
3:30 PM
Maybe the squads are using the wrong implementation of the software
 
Jeez. Someone has a memory :P Well played!
 
Your safe house's address is 123; DROP TABLE RoadNames; -- which offers some degree of protection
@double_wizz Hard to say without an MCVE. If you edit one in, I'll take another look.
 
Please see our room rules @double_wizz. The question needs to be over 48 hours old before posting here
 
@Kevin you would need my university credentials (username and password) to be able to test the code.
@roganjosh my bad, will make sure of it in the future
 
Well that doesn't work either in chat or or the main site
If you're not going to give use your credentials (don't) then you haven't created an MCVE
 
3:41 PM
Have you tried using your code to download a pdf that's available on a public site? If you have, and it only gives you one file as desired, then it sounds like it's a problem with the university website, not your code
 
is it possible to make a cli which takes a [command name] and passes folowing args to that command function with arg parser?
 
@Kevin I haven't tried with a public website with this particular code but the way the two files are downloaded doesn't make any sense to me. One is named as per the code and the other is downloaded in the location specified in the same script. It's like it has divided my instructions on two files.
 
Ok, well, go ahead and test it out on a public website, and if it reproduces the problem, than you should be able to easily create an MCVE that doesn't require your credentials.
@discoMonkey Yes.
 
@discoMonkey You mean argparse? Yes. I believe the concept is called "subcommands"
 
Ok, that's two help seekers all squared away, time for a break
 
3:47 PM
or subparsers, not sure
 
Is there a python library to abstract over the different platform's cache / profile directories? Like it would give you the XDG_CACHE_HOME on unix platforms, the equivalent thing on Windows, etc etc. Maybe it's in the standard library and I can't find it?
 
Not sure if it has the directories you need, but check out appdirs on pypi
 
perfect! thanks so much.
 
parser = argparse.ArgumentParser(prog='greetProg')
subparser = parser.add_subparsers(title='Available commands', metavar='')

parser_a = subparser.add_parser('fruites')
parser_a.add_argument('-t', '--taste', help='a for apple')

parser_B = subparser.add_parser('plants')
parser_B.add_argument('-f', '--flower', help='f for flower')
now i want something like this
script.py [comand] --arg value
 
4:26 PM
If your requirements include the phrase "something like", that means you haven't spent enough time thinking about your requirements
 
4:39 PM
If Python isn't your best language, try writing the program in your best language first, and then port it over. This can be a great way of identifying problems with your requirements, and it can break up the intimidating monolithic problem into little concrete problems.
 
Okay, Im trying to help my sister who is a freshman in CS with some homework. And she sent me this code. From spot testing it works. But it just doesnt look like it should to me. Im sure she did what any good freshman did and found an answer online. dpaste.com/4UQ7QQTRP
its been a hot minute since I have had to think about math and prime numbers haha
 
Why makes you think it shouldn't be correct?
It's certainly not idiomatic, but the logic doesn't seem flawed at a glance.
 
Looks like a pretty ordinary prime sieve to me. First, the easy checks: 1 isn't prime*, 2 is prime, even numbers larger than 2 aren't prime. Then, the factors loop: go through all the odd numbers between 3 and sqrt(num), inclusive. if any of them evenly divide num, it's not prime. Finally, if you made it through the loop alive, it must be prime.
(*controversial?)
As you suspect, there are a million versions of this algorithm online. But I do think it's possible for a freshman to come up with it on their own.
 
@Kevin Got some pretty cheap pitchtorches, if you're interested.
 
Hmm, I can't angrily mob today, my back is sore. Perhaps a less direct role... Does your pitchtorch business need any venture capital?
 
4:48 PM
okay that works for me. I just couldnt make sense of it so wanted to double check it with some experts. Thanks always for the help!
 
cabbage
 
@Kevin I'm trying to keep things small for now. The mob has a tendency to want a refund if you look like the wealthy type.
 
Design your product with special DRM that prevents its use against stately Miyagi manor
 
@ZackTarr Looks like a pretty standard divisibility test for primeness.
 
5:52 PM
anyone know possible cause, a dataframe has no attribute sheet names?
'DataFrame' object has no attribute 'sheet_names'
 
Why would it have that attribute?
 
because it contains xlsx dataframe. i read it here stackoverflow.com/questions/17977540/…
 
The top answer is looking at the sheet_names of an ExcelFile. Are you also using an ExcelFile?
 
df = pd.read_excel(file_path)
print(df.sheet_names)
yes i do it like above
i cannot find it anywhere on google regarding the possible cause of it. i upgraded my pandas already. i just want to retrieve and validate the sheet names inside a dataframe. this dataframe contain the whole file, not just a single sheet. so that I can validate if this file contain several sheets that I want. i also checked the file. it contains many sheets
 
The cause is that the answer is doing xl = pd.ExcelFile('foo.xls') and you are not doing that
 
6:07 PM
i did passed the absolute file path to the excel file. `/path/to/excelfile.xlsx`
I can print the dataframe without problem, only that I could not validate the sheets
here also mentioning the same format that I used which is xlsx pandas.pydata.org/pandas-docs/dev/user_guide/…
 
You're supposed to use pd.ExcelFile and not pd.read_excel
 
I love this conversation
 
ahh i get the wrong idea lol. thankyou.
 
hi! When I show PATH variable content I get /opt/homebrew/bin:/opt/homebrew/sbin: but they're not in /etc/paths file. Where're they supposed to be then? I see both Homebrew paths even if I restart macOS terminal
 
This sounds more like a mac question than a python question?
 
6:22 PM
I was thinking that, but I don't know enough about macs to say so
I don't mind answering a language-agnostic tech question now and again, but, only if I actually know the answer
 
I found this because of pipenv
while trying to set up permanently my PATH
let me ask in a different way
I asume there is only one /etc/paths file and that PATH variable just gets it content from there
am I right?
 
There is only one /etc/paths file, but there are many ways to set environment variables (and PATH is an environment variable)
 
unix.stackexchange.com/questions/356688/… tells me that PATH comes from a number of sources. /etc/paths is one of them, but there are others.
Obv this is for unix and not mac specifically, but perhaps there's some overlap
 
I see...
so, if I try to permanently add pipenv to my user PATH
witch file should I change?
I assume it's /etc/paths but as I'm doing this just for my user, I'm not totally sure
 
(oh, I just noticed the linked question is tagged osx, so I guess it is about mac. That's good, then)
apple.stackexchange.com/questions/358687/… is maybe relevant, but some comments seem to say it's not 100% automatic
 
6:38 PM
*Hi
any idea how can I put multiple conditions in Dataframe filter?
st.table(df.filter(items=['worktree', 'branch']))
I want also to add condition not to present rows where branch contains the value NA
 
So why not use dropna?
I'm 95% sure that filter is going to run in python time. dropna won't
 
what is dropna? :)
 
The pandas method
There's a bunch of methods you can use to mask the df. I've never once used filter. It would be easier if you gave an MCVE of what you're trying to do
 
can you give me example how to use dropna for these 2 conditions?
 
If you gave me an example to work on... why am I the one guessing at what you want?
In any case, dropna can be used in a chained expression
 
6:54 PM
ok I'll read about it. tnx
 
I have an idea for a special optional tier of technical support, which I call the Thunderdome. Unlike my normal half-assed level of support, in the Thunderdome I use my full power to solve the problem. In return, the help seeker must obey strict regulations about the form of their question. For example, there are terrible consequences for: not providing an MCVE, asking "what's an MCVE?", saying "I didn't know there would be terrible consequences :-(" after receiving the terrible consequences
 
What's the terrible consequence?
"Throw him in the pit with Chewie" turned out be to not so bad (god I hate that film)
 
Ideally they'd pay a 100 dollar deposit up front, which I get to keep if there's an infraction
 
Now you're talkin'
 
I don't think anybody would go for that though, so it would have to be something already within my power, like I kick them on sight for the next 24 hours
Since help seekers can only enter the Thunderdome if they have ample time to study the terms of the agreement and freely agree to be bound by them, I see no problem in having cruel and unusual penalties
If you didn't want to be slapped in the face with a herring, don't agree to the herring slap contract and then violate the terms of the herring slap contract
My only concern is, halfway through the public beta, Jon or another mod will come into the room and say "why do my tools tell me that Kevin has performed 100 kicks in the last four hours?"
Don't mind us mods, we've just formed an Anarcho-capitalist enclave within SO's sovereign territory. Nothing to worry about.
 
7:22 PM
@roganjosh my value is <NA> so dropna can't handle it
 
So you have nullable int types but you don't know how to filter the df with multiple conditions? Something's not adding up sorry
<NA> was a comparatively recent addition to pandas and goes against the IEEE specification of nan. Are you copying some tutorial?
xmas party cancelled earlier in this week, and now we're back to remote work outside of exceptional circumstances. Fun times
 
7:47 PM
@Kevin "I didn't expect a kind of Spanish Inquisition!"
 
Complaining about the Thunderdome while inside the Thunderdome is allowed if it is a Monty Python reference
 
8:03 PM
@Kevin oooh I like it!
 
 
1 hour later…
9:06 PM
Vague and opinion-based question incoming: I have a class with a bunch of (internal) methods and attributes that don't really have anything to do with the rest of the class. I'd like to isolate these somehow so that the "meat" of the class stays nice and readable. How should I do this? Extract them into a base class? Or maybe just move them to the bottom and put a delimiting comment like # === FLUFF STARTS HERE === above?
 
@Aran-Fey Without the code, it's impossible to say. Consider a different class/module entirely if that functionality is related. Consider also composition.
 
Base class it is then
 
9:24 PM
what good does base class do
static methods should not exist other than to be called by anyone who has reference to the class
 
@Aran-Fey call it a mixin
 
@AnttiHaapala They're not static methods
 
9:46 PM
@Aran-Fey so what are they?
 
outsource that internal functionality to a helper class and compose it
 
9:57 PM
I can't come up with a good analogy... but essentially the class implements 2 distinct features - the public interface, plus another thing that it needs internally and that's fairly complex. It's strongly tied to the class, but completely separate from the public API.
 
@Aran-Fey Sounds like a separate class in the same module is in order. This will also let you test the two independently.
 
Hmm, I'm not so sure about putting it in the same module. If I want to inherit from it, I have to put it at the top of the file. I'd rather put it somewhere less prominent
 
use comefrom
 
10:17 PM
Is it bad that I don't know what that is?
 
hehe, no
It's the reversed equivalent of goto. So your module would (pseudo-)have
pass

class Interesting(Boring):
    pass

comefrom 0

class Boring:
    pass

goto 1
you'd need actual labels though... :P
 
Why do I never have my crucifix and holy water on me when I really need it?
 
:D
I'm always here to improve your assessment of your current implementation
 
That is, admittedly, an underappreciated service
Have you tried charging money for that? It seems like a solid business concept. The target audience is large enough, that's for sure
 
I'm not ready for my first round of VC funding so it's better to stick to a free alpha for now
And there's a lot of competition in the "crap code beyond reason" market
 
10:30 PM
That is true
 
me again, I'm having another problem, (ps: i read the docs carefully this time)
I got this error when trying to retrieve list of visible sheets on my ExcelFile dataframe
`error message: 'ReadOnlyWorksheet' object has no attribute 'name'`
and I cannot found anything in here https://pandas.pydata.org/pandas-docs/dev/user_guide/io.html#excelfile-class
maybe i should try a new approach with this xlsx file? i checked the read only attribute, it is unchecked and the excel file wasn't protected
 
I can't find anything mentioning a name attribute in the docs, so... again... why do you think it should exist?
 
i did not find anything in docs to validate sheet visibility and name in one iteration. but this guy answer did stackoverflow.com/questions/44581768/…
 
Aha!
> Pandas uses the xlrd library internally
That's a non-truth, ReadOnlyWorksheet is an openpyxl class
 
10:50 PM
tbh i did not understand the full context of it lol. but previously I assume the example is good enough. no extra module imported from openpyxl nor specify the engine for reading the xlsx
I failed to find any alternative. is it worth using openpyxl at the cost of double file reading (multiple files with multiple sheets). just to validate visible sheets?
 
11:06 PM
I don't understand the question, sorry. Why would you read files twice? And what's the alternative if you don't use openpyxl?
 
i also tried this https://stackoverflow.com/a/70200619/7639174 approach from the same question. this time he said it included in newer pandas. my version is 1.3.4. still, no luck with different error message -> ReadOnlyWorkSheet has no attribute 'sheet_state' message
`
and yes, not even in docs have 'sheet_state'
 
Well, the reason is still the same. They're assuming that pandas uses xlrd, but yours uses openpyxl. Maybe just tell it to use xlrd?
 
ok i tried to use xlrd, it seems like it doesnt support xlsx yet
`error message: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead.`
alright its working now, just downgraded my xlrd. and used the first guy answer. thankyou
 

« first day (4071 days earlier)      last day (860 days later) »