« first day (3240 days earlier)      last day (1723 days later) » 

1:00 AM
@smci It's not that I'm not here because I don't want to be here, it's that I can't. I just don't have the bandwidth to monitor the question feed anymore. My interaction with Stack Overflow these days involves looking up questions on Angular and spending 30 minutes each day flagging NAAs. Sorry I can't be of much help, but I've hammered the post in question :)
 
1:20 AM
how do I handle a KeyboardInterrupt while writing a unittest?
 
1:40 AM
I'm going to try with side_effect
 
Abi
A quick question about Python code, I was reading a book that had this Ruby Compiler code (True && False) || True >> True but I wanted to implement this in Python however I am struggling (I am a beginner)
Any directions would be really helpful
 
Abi
2:02 AM
Sorted @abi it's print((True and False) | True)
 
2:18 AM
there's exactly one line that gives me a partial now codecov.io/gh/SwagLyrics/SwagLyrics-For-Spotify/src/…
 
cabbage
 
2:49 AM
99.37% code coverage, except for that one threading line :|
 
 
2 hours later…
4:31 AM
@aadibajpai mock it?
 
4:50 AM
@AndrasDeak had mocked threading.Timer, it gave a partial
 
Mock webbrowser.open(url)
 
5:08 AM
cbg guys o/
 
5:31 AM
where does compiled code resides in after executing any python script ?
 
you're referring to the .pyc files i presume. Usually created in a new folder where the script itself resides
the folder is named __pycache__ or something like that
 
Is it hidden ?
I can't see it on my IDE
I can see on the explorer, Thanks @ParitoshSingh
 
No worries. I never tried accessing one from the IDE though, but i presume the IDE was probably coded to hide/ignore that folder for good reason.
So that one doesn't accidentally run code and keep wondering why changes to code aren't being run perhaps
 
Now that you mentioned, it did happen to me when I was developing Android Apps on Android Studio
one of the compiled code I edited and was expecting to work which eventually did not.
 
^ closed
 
Thanks
 
 
4 hours later…
aws
10:12 AM
ok
 
secret message reader activated
 
<awaits secret handshake before revealing all>
 
awaits for some bribe
 
10:27 AM
awaits eternally, because he still hasn't learned about async
 
Sorry, was busy executing the super secret plan that we discussed and deleted. You'll know all about it... soon.
 
 
3 hours later…
12:59 PM
Are there any pairing functions whose inverse doesn't require me to do square roots?
 
Do you mean the inverse of the result of the pairing function should not give a number which can have perfect square root ?
 
I'm saying that, for a pairing function π(x,y) = z, if I know z I want to be able to solve for x and y without using a square root.
The cantor pairing function doesn't satisfy this requirement because x = floor((sqrt(8z+1)-1)/2) and y = z - (floor((sqrt(8z+1)-1)/2)^2 + floor((sqrt(8z+1)-1)/2))/2
 
1:25 PM
non-sqrt pairing strategy: find the binary form of both numbers
23 = 0b010111
42 = 0b101010

add blank spaces
23 = 0 1 0 1 1 1
42 = 1 0 1 0 1 0

offset one of them
23 =  0 1 0 1 1 1
42 = 1 0 1 0 1 0

combine
?? = 100110011101

convert to decimal
0b100110011101 = 2461
Turning 1461 back into 23 and 42 requires a little bit shifting and modulus, which isn't too bad. But I don't think there's a closed-form solution that doesn't involve iteration, so it's not perfect
 
1:59 PM
Lately on this one blogging platform it's become trendy to organize conversations in reverse-chronological order, so you'll see "I disagree, blue is dumb. Red is the best color" followed by "I think blue is the best color". But some users are sticking with the traditional chronological order. Meanwhile a third of the site has always been complete loonies so they'll write posts that look like replies to things, but really they're just having half of an argument with their imaginary friend.
So now when I read "I disagree, blue is dumb" I'm in a superposition of "is this a non sequitur, or am I about to Benjamin Button my way through a dialogue?" that won't be resolved until I scroll down.
It's a feeling akin to when you are walking up the stairs and you think there's an extra stair and as your foot passes through the virtual stair your life flashes before your eyes
 
Whatever it takes to keep you reading
 
I'm not sure whether this extreme inconvenience is an intentional style choice by the user base, or if the infamously incompetent dev team changed the quoting system in such a way that reverse-chronological quoting is now the default and you have to go out of your way to get chronological quoting
All it would take is a repositioning of the text cursor
 
2:40 PM
@Kevin def p(x, y): return 2 ** x * 3 ** y?
I like to post first and think later
I have a feeling that will blow up
 
I think all pairing functions tend to make z >>> max(x, y) for most values of x and y
 
@AndrasDeak doesn't work, maybe I should make the lambda function a regular one
 
Also not a bijection
 
I was about to say, yeah. But my actual problem only requires a function that's injective and reversible
So I don't mind if reverse_p(5) raises an Exception or whatever
 
I'm still mulling over your binary shifting or some other vaguely similar idea
rbrb
 
2:47 PM
My "actual problem" is "how can I semi-efficiently map an N-tuple of natural numbers to a single natural number?" and it is "actual" in the sense that I actually asked it but it is not "actual" in the sense that solving it will lead to a productive application
 
@Kevin theoretically applied mathematics
 
If you can map a 2-tuple of natural numbers to a natural number, then by extension you can map tuples of any size. But in practice the result will be very large
 
@Kevin Concat lmao
 
As in, (1, 2, 3, 45) maps to 12345? But then how do I distinguish it from (12, 3, 4, 5), which also maps to 12345?
 
oh that's a good point. didn't think about that.
 
2:56 PM
Here is a sample implementation of my binary interleaver. [4, 8, 15, 16, 23, 42] encodes to 5192296858534846147333332324847052, which demonstrates my concern about large outputs
 
Turns out Timer doesn't need a lambda since you can pass args in a separate argument Timer(1.25, open, args=[url]).start()
 
You can usually expect the output to double its number of digits with each additional item in the input
Or, its binary representation will double in length, so its decimal representation will increase by a factor of... log(2,10)? Something like that.
 
@Kevin since you have to pad both numbers to the same length, why not just concatenate them? so (23, 42) => 0b010111101010
 
Dumb concept: convert each natural number to base 9, and use 9 as an element separator. (1,2,3) -> 19293; (1,2,3,45) -> 19293950; (12,3,4,5) -> 14939495
 
100% code coverage :)
 
3:06 PM
@MisterMiyagi I think there's an ambiguity there. miyagi_pair(0b11,0b10) would return 0b1110, and miyagi_pair(0b001, 0b110) would also return 0b1110.
 
huh, I don't ever remember using pairing functions for anything except Cantor's diagonalization argument but now I'm kind of interested in them again. Thanks Kevin.
 
@Kevin as said, you used padding as well. leading 0 must be preserved, or the leading number is always the largest
def miyagi_pair(a, b):
    if a < b:
        a, b = b, a
    return bin(a) + bin(b)[2:]  # plus exact padding I am too lazy to code
 
Hmm, not suitable for my purposes, since I want to preserve order
 
so how would your initial scheme represent 42, 23?
 
Ok. I could be just dumb and not remembering Fourier series, but you could take the Cantor Polynomial and convert it to cos and sin it with 2d fourier series and the inverse would technically not be a square root
 
3:11 PM
Let's see... pair(42, 23) returns 1646, aka 0b11001101110. As you predicted, one leading zero was lost. You can tell because the result has an odd number of bits.
I think it's not an "important" bit though, since unpair can still recover the original tuple
 
what about pair(42, 15)?
 
That maps to 1262 aka 0b10011101110
 
which unpairs to...?
 
42, 15
One possible modification that could be made to miyagi_pair is to preserve leading zeroes by putting a placeholder 1 at the left of the number. Something like return "1" + bin(a) + bin(b) #plus exact padding. The function still won't be bijective since it can't return numbers with an even number of bits, but as I said bijectivity is the property I'm least interested in preserving
 
nope I double checked it, I am just dumb. Fourier series do not work at all.
 
3:22 PM
Perhaps I should expand my requirements from "... without using sqrt" to "... using only integers", which would disqualify cos and friends
pi is not an integer ([citation needed]) so most trig-based approaches are no bueno
 
pi is not an integer but sin(pi) is. :P
actually, before the fourier series idea, I was wondering if there was a way to consider this from the point of view using some thing like sin, cos, or exp(i*theta) because visually cantor's diangonalization visually follows a fairly regular sequence of 90 degree rotation by 45 degree rotation and so on.
 
@Dair Not sen(pai)?
 
3:38 PM
^ ufufufufufu waddup Wayne
 
@Kevin with base == 2 (which we don't really need)
def pir_pair(x, y):
    z = zip_longest(bin(x)[:1:-1], bin(y)[:1:-1], fillvalue='0')
    return int(''.join(chain(*z)), base=2)

def pir_unpair(z):
    s = bin(z)[:1:-1]
    return int(s[1::2], base=2), int(s[::2], base=2)
without base == 2
def pir_pair(x, y):
    z = zip_longest(str(x)[::-1], str(y)[::-1], fillvalue='0')
    return int(''.join(chain(*z)))

def pir_unpair(z):
    s = str(z)[::-1]
    return int(s[1::2]), int(s[::2])
from itertools import zip_longest, chain of course
 
Considerably shorter than my bit arithmetic approach
 
3:54 PM
do you know how can I get the pcbuild directory C:\Program Files\Python37\PCbuild
 
What does "get" mean here?
 
get means how do I obtain this folder in one of my anaconda environments
 
I interpret this question as "How do I get the absolute path of the 'PCbuild' directory within my Python directory, if I don't know what my Python directory is?". Perhaps you could do os.path.join(os.path.dirname(sys.executable), "PCBuild")
 
I didn't install python (just anaconda and I use environments)
I'm trying to run a command from this post github.com/explosion/thinc/issues/92#issuecomment-524538960
but one of the arguments is

"/LIBPATH:C:\Program Files\Python37\PCbuild\amd64"
but I don't have this on my system
 
Anecdotally, I'm on Windows and my Python directory doesn't have a PCbuild folder either.
Perhaps it's only there if you build from source, which I didn't do.
 
4:01 PM
Also, Anaconda will install into another directory
 
yes I know
 
@Kevin generalized
def pir_p(tup):
    z = zip_longest(*map(reversed, map(str, tup)), fillvalue='0')
    return int(''.join(chain(*z)))

def pir_u(z, n=2):
    s = str(z)[::-1]
    return (*map(int, (s[i::n] for i in range(n)[::-1])),)
 
So I think you only need to locate the equivalent that will probably be in your Users directory
 
pir_u(pir_p((314, 8888, 999999)), 3)

# (314, 8888, 999999)
 
Very nice.
 
4:03 PM
maybe its coming from visual studio python development tools
 
<experiencing withdrawals from * addiction>:
def pir_u(z, n=2):
    s = str(z)[::-1]
    return tuple(int(s[i::n]) for i in range(n)[::-1])
 
@Kevin you're right, PCBuild folder is in the source archive for python
 
AFAICT both of our pairing functions are bijective from tuples of a particular size onto N, but not bijective from tuples of an arbitrary size. For example, pair_many((1,0,0)) == pair_many((1,0,0,0,0,0,0,0,0,0,0)) == 1.
I think this can be addressed by representing an N-length tuple as a tuple of length N+1, whose first element is N. Effectively encoding the length into the data.
i.e. pastebin.com/cUmhsm87. Not 100% sure it's bijective though.
 
4:26 PM
hello
 
Hello Hallo
I bet you've heard that one a million times
I bet you've heard "I bet you've heard that one a million times" a million times
 
how strict is the ℕatural number constraint?
 
If you want to map to the integers or something, I guess that's fine. Try to keep it in the same cardinality.
 
just thinking of using zero as a flag of some sort
 
Or uh I guess you don't need to try because mapping to a set with different cardinality can't possibly be bijective
I used 9 as a flag of some sort in my half-joking "convert to base 9" proposal earlier.
It wasn't bijective though since the function can't return numbers with consecutive nines in them
 
4:37 PM
Question: What is the cardinality of the set of all integer tuples of arbitrary integer length?
Challenge Question: create a tuple of non-integer length.
 
My guess is "the same cardinality that the natural numbers have"
 
how can a tuple have a length that's not an integer?
 
@Aran-Fey hence the "Challenge"
 
the tuple (one, two thr) has length 2.6
 
you should upgrade your tuple to 3.7
 
4:44 PM
integers ~ natural numbers (where "A ~ B" means "the set of all A has the same cardinality of the set of all B"), and for any natural number k, (tuples containing k natural numbers) ~ (natural numbers), and I'm 80% sure that (tuples containing any number of natural numbers) ~ (natural numbers), so (tuples containing any number of integers) ~ (natural numbers)
 
I'm convinced
 
Anyone that wants to sink my lazy proof can most effectively do so by going to pastebin.com/cUmhsm87 and finding two arguments to pair_many_with_length_data that return the same number
 
pip install --no-cache-dir --compile -U django
should I always specify --compile and -U
when using pip install?
 
I have never provided arguments to pip install other than the name of the module, and it usually works OK for me
 
thank you very much for your help
I am using it inside docker and I wanted to have it as optimized as possible
 
4:55 PM
Is --compile a new feature of pip? I don't recognize it
 
--compile Compile Python source files to bytecode
-U, --upgrade Upgrade all specified packages to the newest available
version. The handling of dependencies depends on the
upgrade-strategy used.
this is all I know from
pip install --help
but I still don't understand them
what do upgreade if you are already installing the last version with pip install?
 
Bytecode is the intermediary language that the Python interpreter actually reads and executes. If --compile creates bytecode data and discards the source, then I would expect the module to take up less space. It sounds like that's what you want.
I don't think -U does anything special if you're installing the module in an environment that doesn't have an older version of the module already.
 
I'd be surprised if it discarded the source code - you'd have to reinstall all your packages if you upgrade CPython
 
at least I should be getting better performance if not less space right?
 
If you already have an older version installed, then -U will replace the older version with the new version. If you don't specify -U, then pip install won't do anything
(I think)
 
5:01 PM
CPython compiles every file it executes anyway, so there's little point compiling the module at installation time
 
Yeah, if all --compile does is create the bytecode at installation time, then it's only going to save you like 1 millisecond each time you run your program.
And CPython (sometimes?) caches the bytecode in between executions anyway, so you might not even get that much of a boost
@Aran-Fey Just tried it, and you're right. Even with --compile, the .py files are present in the packages directory.
 
the .pyc files are also there whether I specify --compile or not, so I'm pretty baffled about what --compile actually does
 
lol thank you so much guys
 
Theory: Maybe install-without-compile will add the .pyc files if they happen to be present in the .whl it downloads, but otherwise won't bother. And install-with-compile will create the .pyc files if they're not present, and maybe even disregard the .pyc files in the whl in preference for the ones it generates.
 
5:09 PM
hi guys
 
Or, hmm, pythonwheels.com makes it sound like that pyc files are always generated, and aren't bundled within the whl file
Maybe install-without-compile and install-with-compile are identical, and --compile is the default behavior, and the flag only exists so --no-compile isn't lonely
 
yes I was also about to mention --no-compile as well
 
cmd_opts.add_option(
    "--compile",
    action="store_true",
    dest="compile",
    default=True,
    help="Compile Python source files to bytecode",
)
Yep, it's the default.
Conclusion: you don't have to include --compile in your pip install commands unless you want to make it absolutely unambiguously clear to the person reading your install script that it's going to compile
The computer doesn't care either way
 
@Kevin wow I don't know what to say, just thank you so much, too kind! However I believe this was something of your interest as well anyway!
do you guys know what is the best way to use PostgreSQL with Python?
for example with python-psycopg2?
 
5:31 PM
I don't do a lot of DB stuff in Python but I often see SQLAlchemy recommended
 
recbg o/
 
docs.sqlalchemy.org/en/13/dialects/… talks about making sqlalchemy/postgres/psycopg2 play nicely together, so it's definitely possible at least
 
Hi Guys,
Could you please help me with below issue (List append method)

Below script gives recent 'a' value but element is not appending to list. Kindly help me.

area = []
if df.loc[index[i], 'Depth'] == 1: ###Depth 1
    print ("Depth : 1, index :", index[i])
    print ("Total Area : ", df.loc[index[i], 'TOTAL_AREA'])
    a = df.loc[index[i], 'TOTAL_AREA']
    print ("a value", a)
    area.append(a)
    print ("Area value : ", area)
    total = sum(area)
    print ("Sum of Depth 1 is :", total)
 
Looks OK to me. If your conditional passes, then it should definitely be appending a to the list.
There may be a problem with the df object, or in the structure of the code outside of the part you've shared so far. If you can give an mcve, we can investigate further
I will take one wild guess, and say that if your code looks like this:
for i in range(10):
    x = []
    if i > 5:
        x.append(i)
print(x)
... Then you shouldn't be surprised that x gets printed as [9] instead of [6,7,8,9]
 
Okay
 
5:46 PM
@Kevin encode the length of the tuple in a lower base and use one of the extra digits as the flag.
def pir_p(tup):
    z = zip_longest(*map(reversed, map(str, tup)), fillvalue='0')
    return int(f"{bin(len(tup))[2:]}2{''.join(chain(*z))}")

def pir_u(z):
    n, s = str(z).split('2', 1)
    n = int(n, base=2)
    s = s[::-1]
    return tuple(int(s[i::n]) for i in range(n)[::-1])
pir_u(pir_p((1, 0, 0, 0, 0, 0, 1010923, 314, 756, 2103)))

# (1, 0, 0, 0, 0, 0, 1010923, 314, 756, 2103)
Not a bijection but it is one-to-one
To use your '9' flag, you could just have encoded the length in base 9
 
6:04 PM
Hello
cbg
which is a preferred library for multi/parallel-processing
 
The built-in module multiprocessing is fine
 
what about this import concurrent.futures?
 
I haven't used it but I trust all built-in modules to be reasonably performant/stable/useful
 
concurrent.futures performs as advertised
 
is it built on top of multiprocessing?
 
6:21 PM
Poking through the source code, I see that concurrent.futures imports both threading and multiprocessing at different points
 
I just read PEP 3148 which discusses concurrent. It doesn't explicitly state how it is implemented, but I'm going to say that it is not built on top of multiprocessing. IIRC, this came out of Guido's tulip project and from the PEP's language, some multiprocessing magic needs to be moved into concurrent. Plus, concurrent has things like ThreadPoolExecutors, which cannot be dome with multiproc, but rather would need threading
So either concurrent pulls from both, or it has no dependence on either, and reinvents some wheels. Neveer mind. Look at what Kevin said
 
threading seems more "central" to the module than multiprocessing, if such a thing can be determined just by looking at the relative positions of import statements. It probably can't, but oh well.
 
well, ThreadPoolExecutor would need threading. And ProcessPoolExecutor likely uses multiprocessing
 
in that case I will go forward with concurrent
also is there a way to get the optimum/max numbers of tasks/thread I can run on my machine?
one example I saw with multi-processing lib was to use cpu core count
 
Yeah, that's not a bad design. The ideal situation is each CPU core running one thread.
 
6:28 PM
yeah, but you'll have to wonder about GIL
 
Of course, this is impossible for threading threads, since they're usually bound by the Global Interpreter Lock to run one at a time regardless of how many cores you've got
Oops beaten
 
@Aqua4 this is a tough question as it depends on the CPU load per thread (are you hitting GIL? what bandwidths are you saturating? etc). Take a look at this question, which was then answered by none other than Tim Peters himself
 
6:57 PM
One question is "What are you trying to do?" <flies away again for a bit>
 
@Aqua4 exactly ^ "What are you trying to do?"
because "compute a bunch of numbers" has a different answer than "serve a bunch of static files from my computer" has a different answer than "attack the Great Firewall of China"
 
7:45 PM
while we are in the neighborhood of the topic... I run a sql query that ties out against 10k identifiers (therefore I expect about 10k rows) for ONE date. I've been using async to toss out one such query per 200+ said dates. Would it have been better to compose a single query for all dates and identifiers? I think my way is quicker but tbh I haven't tested it.
 
@WayneWerner @inspectorG4dget I am trying to perform few selenium operations on a list of urls, Since there are approx 3k urls and number will always increase I need some speed
 
8:22 PM
 
 
1 hour later…
9:41 PM
@piRSquared query once but have an index on date?
Ah. I reread. There are multiple parts at play, IIUC. You have the query and then the processing in pandas. Then async. I think you're gonna have to just time it on your end tbh
You could always limit the query to be between the max and min of your dates.
In which case, I guess it's a test of groupby vs 200 queries. I'd hope the former wins on speed, but I'm not gonna bet money on it
 

« first day (3240 days earlier)      last day (1723 days later) »