« first day (3800 days earlier)      last day (1373 days later) » 

01:10
Hey @roganjosh. I found you on the menu
01:39
wow, that costs at least 4 times as much the one near my home :p
is roganjosh mild or spicy?
its not that spicy compared to other Indian foods, though I guess that is still spicy to others?
Indians of the relevant region(s) are nuts. Took the one chip challenge with a Vietnamese and Indian colleague. Indian dude ate two chips.
01:58
I am tempted to have one of those, "how bad can one chip be" must probably be what everyone thinks
I ate the chip quickly. It burned my lips, throat, tongue, and more... for five minutes. I felt dizzy, then euphoric. After 10 minutes, I felt fine. For the next 24 hours, every 3 hours, I needed to excuse myself from the room /-:
laurel
All said and done... the chip tasted nasty.
now I really want to have one of these, not sure if I can find one
02:35
So, I found an interesting performance bottleneck but I can't quite find the function to fix it. foo=np.argwhere(big_array == value)[0][:small_number] where big_array is a few terabytes and small_number is like 7. Is there something like "find first n elements?
lol 10 years later
@Mikhail argpartition maybe?
02:50
That performs a deep copy and sorts the array...
So like a no-nonsense approach is to write a for loop that simply finds the value
partial sort... but still probably not
Use Numba for the loop
Yeah, that is a good suggestion but I have spooky development constraints.
that constrain me in strange and unusual ways, which include not adding new libraries
to be clear, you want an efficient way to do this:
def firstnonzeros(a, n):
    k = len(a)
    index = 0
    counter = 0
    indices = []

    while counter < n and index < k:
        if a[index] != 0:
            indices.append(index)
            counter += 1
        index += 1

    return indices

firstnonzeros([0, 0, 0, 1, 1, 0, 1, 0, 1], 2)

# [3, 4]
and all you've got, library wise, is numpy?
Basically, (instead of nonzero id like to run a check against a specific value).
k
I was hoping to leverage this Q&A but it requires you already have a boolean array after having evaluated myarray == myvalue which defeats the purpose.
Sorry, I don't see any other way than just looping.
For completeness, I would have suggested repeated calls to argmax on the boolean array.
rbrb for now
 
1 hour later…
04:35
cbg, is there a pythonic way of doing the following? should I just convert them outside and not have to_something methods?
import numpy as np
import pandas as pd

class List(list):
    def to_numpy(self):
        return np.asarray(self)

    def to_pandas(self):
        return pd.DataFrame(self)


my_list = List([1, 2, 3, 4])

print(type(my_list.to_numpy())) # <class 'numpy.ndarray'>
print(type(my_list.to_pandas())) # <class 'pandas.core.frame.DataFrame'>
If you do it outside rather than making wrapper functions in a wrapper class you eliminate more than 50% LoC. If they were doing something more it might eventually be worth it, but all the above code really does is rename existing functions in a verbose way.
ahh I see, thanks, I wanted to know if there was some python feature to do this a different / easy way
Yeah, just using those functions directly is the easy way, unless you legitimately are doing additional work in the class and functions you're writing. C.f. lambda x: len(x). :P
so if all I do is conversion I can ignore, if something happens before then these are justified?
04:54
Not just conversion; any single function. The expressions that actually do the work, np.asarray() and pd.DataFrame(), have just been moved elsewhere. You'd still need to write them at some point or another either way. The my_list.to_numpy() way isn't even shorter. You could perhaps do n = np.asarray etc. if you plan to refer to those functions frequently.
now it makes sense, thanks
 
2 hours later…
06:57
@Aran-Fey, @Kevin it works like a charm, thanks !
 
1 hour later…
08:14
@python_user seems like a good use-case for functools.singledispatch. That is assuming you need to do this for more than one type and more than one implementation.
I will check the docs, first time hearing about singledispatch
On another note: How are people handling linters/checkers/tests for contributors in their repos? We always have the CI check everything, but are unsure how much to put into pre-commit or pre-push hooks.
Right now we're either "everything in pre-commit" or "nothing in pre-commit" but neither is satisfying. The pre-commit route is a bit heavy and often times I'd rather have people commit partial things instead of finishing them – TTD comes to mind. The unchecked variant allows much smaller commits but often requires fixups.
 
1 hour later…
09:41
Hey guys anybody got any knowledge on how to get flask mongoengine to connect to a mongoatlas cluster? I have tried setting the host to the corresponding cluster uri but not connecting
found an entire issue on it here github.com/MongoEngine/flask-mongoengine/issues/247 but doesn't seem to have been resolved
@MisterMiyagi that's something that always comes up in my projects as well. Currently we do "no pre-commit" everywhere and just document the toolchain, for the reasons that you also gave. We squash feature branches, so messy commit history doesn't matter.
Is there a VCS where a "branch" is not just a particular commit, but rather a series of commits? With git, you create a feature branch, make some commits in there, and then you can either merge all those commits into master, or you can squash them into a single commit and merge them into master. There's no way to leave the feature branch as-is, but only make one commit to master, is there?
@Aran-Fey just create another branch (pointer) on the tip
On the tip of the feature branch? And then what? How do you merge those changes into master?
in git there's no commit in isolation
@Aran-Fey and then merge the other one.
09:55
But then all the commits from that branch will show up in master
@Aran-Fey Sounds like a squash on merge is what you want. The initial branch will remain as-is, but the master only gets one commit.
@Aran-Fey squash them
"what goes into master" and "what happens with the feature branch" are two independent things, actually
merging the feature branch doesn't destroy your feature branch, only removes the pointer to its tip
and the pointer doesn't go far: ~master or something like that should be that former tip
Ooh, so squashing doesn't destroy the commits you squashed?
(~)Nothing destroys commits!
I only ever do squashing via github/gitlab UI, so not sure if GH/GL squash merge is some magic on top of regular git. shrug
09:57
You have to remove pointers to commits (encompassing all linear history) and then prune them to lose it.
if you take a commit hash (possibly from git reflog) that was in your feature branch, you can still check it out after you've merged that branch
I see, I see, thanks
If you look at the learngitbranching game, merged commits actually stick around, faded out :)
I should probably check out some of the git workflow tools people have made, like gitflow or whatever it's called. Squash-merging every feature manually sounds like a pain
Pain compared to what?
I mean is your issue squashing, or just merging in general?
Compared to fast-forwarding every feature into master and creating a mess, which is what I've been doing ever since I started using git
10:02
Merging is a single command. The hard part is fixing merge conflicts, but I'm not sure tooling can give you a lot there.
I might be missing your point
Hmm, let's see if I can explain this. Basically, it's about granularity. I want every commit to master to be a complete feature/bug-fix/whatever. But in reality, while you're developing that feature, you're gonna make a whole bunch of commits. I don't want to lose those, but I don't want them to show up in master either. So every feature branch would need to be squashed, then merged into master
OK, but that all works?
Use feature branches, squash merge them but keep a pointer on the branch tips
git checkout feature
# hack hack hack
git commit -m 'forgot one'
git checkout -b feature_to_merge
git checkout master
git merge --squash feature_to_merge  # or something, I've never squashed in git
Sure, but from what I can tell, squashing seems like a bit of a headache. Do I have to count how many commits I made in my feature branch?!
no
it does the same thing as merge but only creates one commit
git assesses the shared history
you could easily test in a small example repo
Oh, there's a --squash flag for merge? This tutorial I'm looking at is talking something completely different, then ._.
10:12
@Aran-Fey If you are managing the repo via GitHub/GitLab, you get the entire icky parts wrapped by a very nice and useable GUI. I basically only do git add/commit/tag/branch via the command line. The rest is exclusively via GUI; feature branches are always eventually a Merge/Pull request and squashing them is a click of a button.
@Aran-Fey hold on, it doesn't do what I thought it did
I've got a whole bunch of projects that aren't ready for github, unfortunately :(
That was a lie. I occasionally use git init. fetches the hat of shame
@Aran-Fey free private repos
@Aran-Fey You can start with private repos if you feel the horror is too much for mortals.
10:14
I think I might write a small command line tool that does all the branching/merging for me, maybe even auto-update the version number while I'm at it...
Always remember the one important lesson to be learned from SO main: other people do worse; much worse.
hahaha, ain't that the truth
@Aran-Fey OK. So you don't even need an auxiliary branch.
The way you use it is git checkout master; git merge --squash feat; git commit, after which you can edit the squashed merge commit message. The original feature is left intact.
Wait, you have to commit after merging? O.o
my hand are full to copy a full example
@Aran-Fey with --squash yes
that's what tripped me up at first
it kind of makes sense because it replaces history for the former branch
10:18
@AndrasDeak Whew, I panicked for a second there
and it works better for your use case, might actually be the reason (i.e. being a common use case)
Alright, I'm definitely automating this. What's the consensus on keeping old feature branches around? I'm worried that'll create too much clutter in the long run
post merge? we remove branches on merge. but i think we've established im no authority on the subject
also cbg!
Previously we cleaned them up, but these days I just keep them around. There's practically no extra weight to old branches.
Just wait until a git branch produces 200 lines of output :P
10:27
True that. At times I clean up locally.
The remote gotta have them all.
11:04
Is it a pokemon thing?
I just want to be prepared for GitHub achievements.
Why is it that syncing your data between multiple computers makes you more likely to lose something -.-
Looking at you, nextcloud
I was initially wary of synchronised cloud storage services when they became a thing. (Nothing's changed since.)
my intuitive often doesn't match the intuitive of service providers
 
1 hour later…
12:32
Hello, is anybody online?
12:50
Hello, I dont think so :p
cbg all, bugrit
[considers switching from Foul Ole Ron to SpellMeOwnNameWring Dibbler]
I found the BITS(https://biosbits.org/) project, which stands for Bios Implementation Test Suite. The creators managed to allow python to access low level functionality of hardware and run directly without relying on a separate OS. As it is written on their website's homepage:

> BITS supports scripting via Python, and includes Python APIs to access
> various low-level functionality of the hardware platform, including
> ACPI, CPU and chipset registers, PCI, and PCI Express. You can write
> scripts to explore and test platform functionality, using the full
(see full text)
Wait, did you just ask "how do I code an OS in Python"?
I recommend async
13:07
How do I use BITS to code an OS with python?
IIRC David Beazley had an introduction on how to use coroutines can be used to do basic "OS tasks" like task switching and IO.
No, a full os
Is there a way?
Well, yes. You learn how to implement basic OS tasks. Then you implement that in Python. Then you run that with BITS.
thanks. what is async?
A term you should look up before attempting to build an OS.
It's a means of cooperative concurrency.
13:09
Only thing google shows me is that it's a js function
In that case, I recommend to brush up on your google foo as well.
You will need it.
All os dev guides are 90% assembly and 10% C. How will I learn to code an OS with python? Any links to guides? Any tips?
Well, yeah, of course they're all assembly and C. That's the only sane choice. That doesn't mean you cannot do the same in Python (minus parallelism, perhaps) but you will be interfacing with things that are only talked about in assembly/C terms.
So how do I understand how to do it in python
No guides, no support forums, no books. What do I do?
By taking the time to learn it.
13:14
Any helpful links for me?
That's, uh, also the point where you should at least note the hint that other people don't do that in Python.
Lol
@WhiteWood please stop
We can't teach you how to write an OS in python. Good luck with the project.
@AndrasDeak Sorry for seeking help here. I didn't mean to disturb you. Thanks for wishing me good luck
@MisterMiyagi @AndrasDeak So is there nothing I can do...
9 mins ago, by MisterMiyagi
Well, yes. You learn how to implement basic OS tasks. Then you implement that in Python. Then you run that with BITS.
Thank you
Bye
13:18
Bye
FWIW, now I feel less bad for trying to bootstrap a parser <do MM's random project of the day>.
Quick one: how can HTML attributes be passed to {{ wtf.quick_form(form) }} when working with flask-bootstrap and flask-wtf. Technically, the documentation states that the use of {{ wtf.quick_form(form) }} is best for creation of forms on the go (I mean very quickly). However, to have more control, manual creation of forms is recommended.
I understand that, but I trying to pass HTML attributes such as id and class to a form using the method {{ wtf.quick_form(form) }}. This how the forms can be made dpaste.com/F97SJT3JF
Is it achievable? I have found out that key words can be passed to a form as follows:
`username = StringField('Username', validators=[DataRequired()], render_kw={"placeholder": "Username"})`.
It would be great to add a class or an id just like placeholder. but apparently that does not work
13:43
morning cabbages, folks
14:10
Is reversed({0:0, 1:1}) guaranteed to work since 3.7?
I've got 3.7 installed, it doesn't work there
works in 3.8 though
Thanks. The painful way it is, then.
You mean vendoring a patched 3.7 version that's pulled and built by your setup.py? Yeah.
14:54
Hello, first time in the chat.
cabbage :D
Hi all. Are questions asking for optimization to working code/snippets On Topic?
ƪ(ړײ)‎ƪ​​
15:14
I think code review would be better for such requests
@anky Do they have a strict On-Topic criteria? I'll go look again.
I haven't noticed anything strictly saying it is not on-topic in SO either.. but that's my general idea. :) you can check this: meta.stackexchange.com/questions/211788/…
@wwii yes
201
Q: A guide to Code Review for Stack Overflow users

durron597You're on Stack Overflow and you've found a question that seems to be about improving code. You are trying to be helpful, and you put a comment in the question: You should try asking on CodeReview.SE instead. —YourName 2 minutes ago … and suddenly, out of nowhere CodeReview.SE users swoop i...

cc @wwii ^
15:23
how can I make 11.720000000000001 to 11.72 and 1.1499999999999999 to 1.15 Before adding them in my list they were fine :D
@CătălinaSîrbu they are fine as-is
Format them for printing if you want to
does code review get the same level of regulars? my first and only question so far at code review only got answers after I bountied it :/
@CătălinaSîrbu have you tried round(float_num, 2)?
@python_user no site matches SO in traffic
@AndrasDeak Thank you. :) I really needed this I think. Needs some time to process all the info.. Will consider this in future.
that would make sense, I did not even know there were other sites when I started college, I thought the other stackexchange sites where fakes of SO for different topics :D
15:27
Yes I have seen them do that before so I try not to blanket refer to CodeReview. Why does the Close because it belongs on another site option only have four sites listed?
...@anky
@python_user thanks
@wwii so as not to overwhelm small sites with off-topic noise
@CătălinaSîrbu Andras' point still stands, rounding off when printing
SO is so much larger that just a splinter of its traffic redirected to a small site can overwhelm it
So the A guide to Code Review for Stack Overflow users on the CodeReview meta is pretty straightforward - Codereview is just that more of an open ended Q&A asking for generalized critique.
thnx
15:36
yes, and one should generally not redirect mediocre questions there
And code review is still on topic here
I mean code optimization questions
A while back, months/weeks, I got a pop-up survey on how I perceive down-votes. Was that most likely a random selection or a result of my liberal down-voting?
Specifically what I think it means when I down vote.
I didnt get any, maybe it could be a 5k or 10k + rep thing
@wwii I think that was specified on meta. Don't remember.
But they planned to ask ridiculously few users if memory serves
@wwii see meta.stackoverflow.com/questions/402061/… (random who downvoted)
15:51
My Meta search satisfaction hovers around 50 percent.
Internal search is useless
16:06
Although I have to say that reading on meta does inform me even when there are highly up-voted conflicting answers/opinions. re: Internal search is useless .. use search terms site:meta.stackoverflow.com?? Oh yep first answer.
Heh, I did a search for whether it's possible to write an OS in Python and found an answer from none other than Antti :)
@WhiteWood duplicate of your question ^
he has said this is not a duplicate in his question 0_O
oh, sorry
the exact wording is present in his question on main, not the version he posted here though
16:19
Was there a question on main when they asked here?
hmm, yes, aske 12 hours ago
I guess, I thought you would have moved so I didnt tell anything
@python_user what?
I mean, you are always the one to check if the user has posted on main :D
so you didnt move, so I thought it was not a question
weird conclusion
I will admit that
16:51
It's time for Vague Questions: I have a vendor that has delivered a python API via pyc files. The problem is, I can't install these into other environments with different versions of Python. What is a simple workaround to make those API calls available to a new updated Python env? If a simple workaround isn't available, what is any workaround?
Should I write a goofy wrapper that takes re-creates the API and makes system calls? Should I try to reconstruct the py files from pyc files and install in the new env?
I'd probably reconstruct py files out of spite, but I'm speaking from the peanut gallery
You zeroed in on my exact reaction. I might still.
 
1 hour later…
18:08
how can I increase the speed of this algorithm ? maybe use some vectorized stuff?
def find_shortest_path(self, start, end, path=[]):
    path = path + [start]
    if start == end:
        return path
    if not start in self.graph:
        return None
    shortest = None
    for node in self.graph[start]:
        if node not in path:
            newpath = self.find_shortest_path(node, end, path)
            if newpath:
                if not shortest or len(newpath) < len(shortest):
                    shortest = newpath
    return shortest
This might not be the best place for it, but since it’s somewhat connected to Python, has anyone here worked on NLP in the context of application testing?
I mean I found a better approach but I got the eroor
TypeError: 'int' object is not iterable on the q = deque(start) line
def find_shortest_path_liniar(self, start, end):
    dist = {start: [start]}
    q = deque(start)
    while len(q):
        at = q.popleft()
        for next in self.graph[at]:
            if next not in dist:
                dist[next] = [dist[at], next]
                q.append(next)
    return dist.get(end)
because both start and end are integers
my graph looks like this
{1: [111], 2: [9], 3: [101], 4: [10], 5: [112], 6: [11], 7: [134], 8: [139], 9: [3, 5, 7, 8], 10: [5, 7, 8, 1], 11: [7, 8, 1, 3], 12: [1, 3, 5]}
18:26
no idea if yours is good or not, but you might as well use networkx for any graph related algorithms: networkx.org/documentation/stable/reference/algorithms/…
@davidism could you give me a hint how should I adapt my code ?
remove all your code and replace it with a networkx graph and function call
i don't understand how to create a networkx graph
I'm not going to write that for you, if that's what you're asking. It's described in detail in the documentation.
the shape
ok I got it
@davidism thanks
18:44
howdy folks! It's been a hectic day. How's everyone doing?
19:00
o/
Since you asked... Relieved and annoyed both at the same time. Relieved because my new motherboard came back from its BIOS update and actually works with my new CPU now, and annoyed because that means I have to reinstall everything on the new PC
...and first, I have to backup my data over a 100KB/sec wifi connection
@Aran-Fey no chance for ethernet?
Or an external drive?
19:16
My ethernet stopped working recently, no clue what's up with that. But I could temporarily move my PC to my brother's room (where the router is) I guess
For now, my plan is to hope that not much changed since the last backup, so it won't have to transfer too much data
yikes! that sounds really tedious. Do you happen to have a USB-3 ethernet port adapter?
Nope. My only hope for LAN is a powerline adapter, but it's refusing to cooperate
Plan A: Patience. Plan B: USB tethering via my phone. Plan C: Moving the PC closer to the router. Plan D: Losing all the data that changed since my last backup
19:31
@Aran-Fey I heard that how well those work depend a lot on the wiring in the house
It used to work... a while ago, and on Windows. For some reason linux never managed to connect to it
now that's weird
Might have something to do with your ethernet not working at all anymore?
Possibly. I probably should've given it a shot, with the new mainboard and all...
20:31
Hi, everyone
Nice to meet you
Who can help me in django?
`AttributeError: 'SimpleAPI' object has no attribute 'get'`
I faced this issue in django project.
@GretchenRichards Hello. I don't know django but I suspect others who do would still have to see some code, preferably an MCVE.
20:47
@FélixGagnon-Grenier
Hi, How are you?
Sorry to bother you. Could you help me on django?
please do not ping random people in chat.
That being said, nice being back here o/
@GretchenRichards as Félix said, please stop pinging random people. That's not nice. Let's start over. Please read my first message to you.
@GretchenRichards Instead of pinging people randomly, your time would be better spent providing more details about your problem. If someone can help, they will. If not, your pinging won't change that.
My django project is running in docker container.
And I am making the rest api
When the api is calling, there is a issue like this
20:58
Neither of which are really relevant to the error that you have got. You need to show the code that raises the error with an MCVE as asked. Please also see the room rules though before posting
AttributeError at /api/method/
'MethodAPI' object has no attribute 'get'
You've just re-stated the problem. We cannot see the code you're using
21:34
Proving once again that people will do anything to get help, except provide the information you need to help them
22:01
@Aran-Fey I tried those but eventually settled for a mesh network, which is OK if you have the cash and there are n long distances involved.
22:14
@CătălinaSîrbu Floating-point numbers can't represent all decimal values exactly; the trick is to use formatting techniques to display the numbers to the precision you want. If you're familiar with the f-strings, you will find that after g = 11.720000000000001 the expression f"{g:8.2f}" evaluates to ' 11.72'.
An older equivalent is` "{g:8.2f}".format(g)`, which does the same thing in a more verbose but backwards-compatible way.
(field-width 8, 2 decimal places).
Anyone with more database experience than me know why I might be getting this error with psycopg2?
psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block
I've read this, but it doesn't look like I have a failing query before the one that causes the error
cbg
if i have functions like:
@inspectorG4dget isn't the one causing the error the failing query?
22:29
not according to that link (unless I misunderstood). Evidently, if a query left the db in some error state, a subsequent query might cause such an issue. That being said, I've been able to run the error-observed query independently and it works
def f(x):
   try:
       logging.info()
       #function stuff
   except Exception as e:
       #exception stuff
       logging.info(e)
@inspectorG4dget I don't know databases, but to my layman's eyes it seemed to say "every subsequent query will raise that error" but it doesn't say whether the original failing query will raise it. If I were designing a library I might tell the user that subsequent queries will be ignored right when the failure happens.
how could I do a regex in vscode to select them. I was trying `def.*(.*):[\n+\s+\W+]+.*logging to see if i could get there but this doesnt do a greedy matching
I have a lot functions i've just been asked to reorganize and i thought itd be interesting to select them all at once
@AndrasDeak that seems very logical, but "This is what postgres does when a query produces an error and you try to run another query without first rolling back the transaction". My interpretation is that what causes the traceback on stderr is the "another query". In the try-catch, a `cur.execute("select 'hi'") fails. Am I just missing something super obvious?
If "a lot" is several hundred, maybe look for an automated solution, but if it's thirty, it will probably be quicker to manually search them out and edit them. I speak from experience ...
22:36
@inspectorG4dget I just don't take such claims without citations for granted. You never know if the person just phrased it sloppily, or was plain wrong. The question doesn't focus on the number of errors, it's just "I keep seeing errors", "yeah, you have to roll back first". Just my general caution toward anything I read online without convincing proof. Because my premise is that what you see contradicts the answer. Either you're wrong or the answer (or our interpretation of it) is.
@both: that's totally fair. I've also edited all the preceeding queries to return a singular row. So now I'm really screwed up
@holdenweb manual replacement is probably also less prone to giving you dawizards
@holdenweb yea, had to do this for like 60 or so functions before and I made it work once, this time its just 28 functions across a few files im just annoyed at myself for forgetting
i can get an easy compromise of semi manually doing it by just doing def.*(.*):
Doesn't your IDE let you move easily to functions/methods?
is there a way to get the last n queries from a psycopg2 cursor?
22:45
If there's a way to do it in vscode im having a hard time finding it
what is good write-to-db architecture? should I create a cursor once and pass it to a function to write each of many queries? or should I let the underlying function create a new cursor for each write?
ok so it looks like there was an issue with some query not fully committing. I enabled autocommit on the connection, and that solved the issue
23:05
omg wtf, i just came across a 100 lines of if/elifs
46 elifs
why would they not just use a switch case
@Skyler probably due to the lack of a time machine
i mean its extra scary here cuz this is an operation that i think is getting applied to a pandas dataframe one element at a time
thats like 30-50x overhead isnt it
That part might be on the devs. Lack of switch in the code is not really their fault.
oh dear god! that's a lot of individual row handling
yeah, but the switch/elif construct may in fact be inappropriate for a df
23:22
ill probably refactor that into something like series merge of the input col with a matching series so the entire thing can be vectorized
@inspectorG4dget its even worse because df.apply is also generally an iteration so its looping with all this overhead
or at least add the switch case
@Skyler I looked, and eventually uncovered a neat little system that lets you navigate the Python tree.
hmm, do tell
Couldn't find an documentation on it, but it's there!

« first day (3800 days earlier)      last day (1373 days later) »