« first day (3740 days earlier)      last day (1224 days later) » 

12:14 AM
Hello everyone! Is there any way to parallelize / improve the performance of Python code automatically, through some library?
Correcting: improve the performance of Python code or parallelize the code (...)
 
 
1 hour later…
user12582392
1:23 AM
hey guys, i
 
user12582392
i'm trying to do a very simple ML training, the main problem being the data. So far I got an algorithm that downloads images frm the web as JPG, in the same size
 
user12582392
I just don't know how to proceed, to import this JPG as a dataset
 
user12582392
images = [jpg1, jpg2, jpg3...] any ideas? My guess was to convert all images to a h5 file, but there is nothing out there as to where to start :-(
 
1:50 AM
@AndrasDeak thanks Andras, "This edit conflicted with a subsequent edit." was what it said, someone else did remove the 3.x tag though
 
 
4 hours later…
5:43 AM
cbg
what happened to @piR2? Has anyone seen him recently?
 
 
2 hours later…
8:10 AM
@Marco The only drop-in solution is PyPy, but not all libraries work with it. There are various compilers that work with minimal code changes, such as Cython, numba and others.
I've heard good things about nuitka but never seen it in action myself.
 
8:46 AM
@roganjosh I am trying to work out whether this is an ironic case of "no one will ever need more than 640K", or proof that the len limit is indeed big enough.
 
9:05 AM
@piRSquared You doing ok?
@Marco What type of code? CPU-bound or IO-bound? Array computations, string processing, web...?
 
 
1 hour later…
10:13 AM
@python_user that means you didn't do anything wrong, it's just a clash between your edit and a 2k+-rep user's edit
 
 
1 hour later…
11:16 AM
Happy monday guys!
I'm not sure about a statistical problem I've got: I'm doing a kdeplot with seaborn to check if a variable has impact on the survival of a company. In my dataset I have around 600 died and 400 survived company. So I'm not sure if I can tell the impact of the variable actually. Because if the plot "tells" the variable has to be low to actually survive it could be false because the dataset (died/survived) is uneven(600/400)?

Does it actually matter?
 
11:28 AM
probably yes
 
Would you also say if the data (died/survived) differs around 5%? @Hakaishin
 
Do you want to do science or horoscopes? Just because the effect is not small doesn't mean it doesn't exist. And sometimes we reach the limits of our models and can't differentiate between effects and errors, but this seems more like a case where you should read up on the relevant statistics. Don't ask me I have no clue what the search terms are, but something like unbalanced datasets or so.
 
cbg
what sort of encoding is that: (from a .txt file) - if someone knows?
b'6\x08\x01\xc8\xfd\r\x02\xb4\xf31\x03\xc3\xf7?\x01\xb7\xa8C\x02\xd2\xaa_\x01\xb7\xc9n\x01r\x011\t\x010\n'
I read it as bytes, but it should be Chinese chars - however, I don't find the correct codec.
 
chardet says it's GB2312
 
Thanks @Aran-Fey - it throws:
`'gb2312' codec can't decode byte 0x82 in position 51: illegal multibyte sequence`
 
user13727121
12:11 PM
how do i specify the number of decimals i want using this % specifier. For example, you package weights %d % (weight). The input will be 4.8, but it only appears as 4
 
%d means integer format. it never has decimals.
use %.1f to get one decimal place.
 
user13727121
thank you
 
user13727121
hmm, this {}.format() works too. "Your package weights {}".format(weight)
 
I recommend to use f-string formatting unless you have a clear reason not to.
Either way, the syntax for format/f-string and decimal places is practically the same as for printf/%. Try f"{12.31:.1f}" for example.
Hm, I smell an opportunity for code golfing...
 
user13727121
12:29 PM
@MisterMiyagi awesome, that works! Interesting, there are a lot of solutions to use and no matter what, it produces the same result
 
user13727121
I've always stick with this approach "{}...".format()
 
That behavior where modules can replace themselves in sys.modules and the import statement will return the value from sys.module is not an implementation detail, right? Basically I need this kind of thing to work:
# bar.py
import sys
sys.modules[__name__] = sys

# foo.py
import bar, sys
assert bar is sys
 
Seems to be the case as per Import System - 5.3.1.
 
@Aran-Fey decently sure it's in the docs. Data Model if I'm not mistaken.
 
@metatoaster I don't think that applies here; I'm modifying sys.modules while the module is being imported. This means that the import machinery has to check sys.modules twice: The first time it checks if something with the name "bar" is present in sys.modules, and then after it has finished executing bar.py it looks at sys.modules again and returns the value that's stored there instead of the actual bar module
 
12:38 PM
here's an example in the docs: docs.python.org/3/reference/…
 
That's also different from what I'm doing though. That modifies the existing module object, it doesn't completely replace it
 
ah, I see. need to check whether there's anything for that in specific.
 
Good enough for me. Thanks
 
1:13 PM
Hey guys I have my first backend python developer job interview this week, any advice? also what sort of task should I expect them to set in it, as it says they will set a task for me to do...
 
@Aran-Fey Guess you don't want the docs that call this implementation specific, then?
 
:(
Oh well, I changed my library's interface a bit and it's probably actually better now
 
2:04 PM
@AndrasDeak ahh thanks for clearing that out :)
 
@Kwsswart 1) don't forget that you're also interviewing them; get a clear idea whether you want to work there or not. You should get time at the end of the interview where you can ask questions. 2) don't be afraid to have an opinion, but if you're proven wrong, or told "we don't do that here", getting pouty or argumentative is a very bad look 3) showing that you are a good learner is usually more valuable in live-tasks than showing that you know how to solve the task
 
@Arne Thanks for the tips I am going to spend the evening researching to learn more about them, very nervous for it but will just try my best and see what they ask its a multiple stage process so may not even get to the challenge stage but hope to
 
best of luck!
 
2:26 PM
@Kwsswart Good luck!
 
Thanks guys will let you know how it goes
 
3:06 PM
late morning cabbages, folks
 
3:42 PM
hello guys! I really need your help! I've been trying different ways but nothing worked... is there anyone who can help me with my problem?
 
@eitan102 Please read the room rules. Questions from main should generally not be posted here for at least 48 hours.
 
got it Matt! thank you!
 
You're welcome to ask if you don't get a satisfactory answer in 2 days :)
 
4:25 PM
what an atrocity
 
4:55 PM
cbg
@MisterMiyagi thanks for all the recomendations!! I will try PyPy first, so.
 
Hi Everyone.. I'm trying to think of a best possible way to do a mentor mentee matching program... Any suggestions?
 
@ThomasKennedy I suggest a more in-depth problem description.
 
@smci thanks for responding. I believe that in this case there are two types of processing (cpu-bound and io-bound). Images (files) are generated from arrays.
 
5:24 PM
@AndrasDeak Indeed. Just one close vote? Bah!
 
5:40 PM
Hi everyone,
just posting this thread in case someone has experience with both Celery and Selenium webdriver with python

Thanks ;)
https://stackoverflow.com/questions/65656175/keep-selenium-webdriver-across-celery-tasks
 
5:51 PM
Hey guys, I am relatively new to python. Would be nice to get some help with imports from my notebooks. I keep getting this error: "No module named 'strategies'"

./cbsm     <--- project root
   __init__.py     <--- empty file
  notebooks/
        __init__.py    <-- empty file
        my-notebook.ipynb    <--- from strategies.MyStrad import MyStrad
    strategies/
        __init__.py   <--- empty file
        MyStrad.py   <--- contains class MyStrad
 
@ChristophBühler please see our code formatting guide for chat
 
@AndrasDeak thanks. is this ok?
 
yup, thanks
You'd either have to have strategies to be absoutely importable, i.e. installed separately, or use a relative import
Does from ..strategies.MyStrad import MyStrad work?
 
"attempted relative import with no known parent package"
print(_ _ package _ _) # "None"
 
Hmm, that's a notebook file, which is something I'm unfamiliar with
it might behave as if you executed a module in the same place, which might not also not work
 
5:57 PM
hmh
 
So perhaps you should install strategies separately. Might even make sense.
 
Should I do that for every folder my project has?
 
I don't want to comment because it might be possible to fix it at the place of the import. I'll defer to those who know python packaging a lot more.
 
ok, thank you for the help!
 
6:13 PM
as a rule of thumb, do not mix executables (scripts, notebooks) and libraries in the same package hierarchy.
Either ./cbsm should have no __init__.py (in which case the import path should point at ./cbsm) or it should not contain the notebook (in which case the import path should point at ./ and you import cbsm.strategies).
 
@MisterMiyagi just so I understand you correctly. Are these assumptions correct?
a) if there is a __init__ file, the folder becomes a "package"
b) if you do "setuptools.setup(name, version...", you get a "library"
c) libraries are useful for shared code across multiple projects ("pip install xxx")
 
6:37 PM
@MisterMiyagi That number is a little on the ... extreme ... side :)
 
@MisterMiyagi thank you. I came to my senses and restructured my project :D
 
7:14 PM
@ChristophBühler yes to almost all.
a folder without an __init__.py is a namespace package.
That's one of those pretty cool and nifty things that... most people won't ever need.
 
@MisterMiyagi I will look that one up :)
Should I name my class files with upper camel case or snake case?
 
I personally recommend against using one file per class, so can't really comment past "neither". If you really want to, follow PEP8 – module ("file") names should be snake case.
 
File names (module names) should be named in snake case. There isn't really a "class file" type - it's not Java where you have one class per file. PEP8 describes the conventions, but the Google style guide is, in my opinion, more succinct/clear in how it's presented (and I think in-line with PEP8)
 
7:29 PM
@roganjosh did they always recommend indents of 4 spaces? I thought they recommended 2. puts away pitchfork and torches
 
I think they have indeed changed that. I recall someone mentioning something along those lines.
I use two spaces for TeX files by the way
 
@MisterMiyagi for indentation, I'm not entirely sure. Certainly things like tensorflow were on 2 spaces. But I should have been more clear; I think the Google style is clearer in the way it conveys naming conventions. I haven't cross-referenced it with PEP8 in other aspects, sorry
 
@roganjosh It's fine. You can still hand in your essay on the differences of naming conventions across the ages by tomorrow. adjusts monocle
 
You are most kind, Sir
 
@AndrasDeak Same for me with Puppet. Writing Python code templated by Puppet is weird, though.
 
8:30 PM
@MisterMiyagi 2 spaces for internal projects, 4 spaces for public projects.
 
fetches his trusty pitchtorch
 
lol "pitchtorch"
 
Pitchfork imbued with flames and machine learning?
 
all the pitchforking and torching you ever wanted to do, in one handy tool! order yours today!
 
Oddly, I'm reminded of the old classic TV shopping advert
 
8:35 PM
LOL
 
cabbage!
 
cbg
@roganjosh Admirable how the guy just keeps on advertising...
 
Trooper
There's a split second when he bites the dust and it reminds me of a trout or other fish being landed. But there's no doubting his professionalism :P
 
Good thing colours were scarce back in the day, so blood wasn't too obvious
 
reddit just asked me if r/tensorflow has profanity in its name. wat?
 
8:46 PM
well it has w and t and f
 
not in that order!
 
Constant vigilance!
 
although I guess the order given is how i read the question. tf, w?
 
<shields eyes and ears> Never before have those letters been uttered in Room 6
 
9:06 PM
hey folks! I have another sql question. I seem to have weird postgres requirements:
I have two tables: tableA(columns a1 and a2) and tableB (columns b1 and b2). I want to add a foreign key in tableB (b1 references tableA.a1), but I'd also like to add a check such that tableB.b1 references tableA.a1 in a row where tableA.a2='someValue'

Is this even possible?
 
Sure it is. What's your query?
 
how do I do this?
 
You can create a temporary table using WITH and left-join on it
 
not sure I follow. Could you please expand?
 
I'm not gonna code it all out mate, I think the onus is on you to give me some setup
 
9:12 PM
fair. But I'm kinda clueless here. I can write up the foreign key constraint:
 
You don't need an FK constraint to do the join. You can specify the keys that the join is performed on
 
create tableA
(
    a1 = int,
    a2 = int,
)

create tableB
(
    b1 = int references tableA.a1,
    b2 = int
)
but the problem is that while b1 has a FK constraint to a1, it does not check a2
 
Doesn't check a2 for what?
 
I want to make it so that the insert (into B) works not just on the b1=a1 constraint but also on the condition that there exists a row in tableA such that b1=a1 and a2='someVal'
 
So that's a WHERE that you can add after the join
 
9:16 PM
lemme see if I understand you correctly:
select count(*)
from tableA as A, tableB as B
where A.a1 = B.b1
  and A.a2 = 'someVal'
is this what you're suggesting I do?
 
No, it's not. But you want to just get a count?
 
no I don't want the count (I used that for only demonstrative purposes in that query). I actually want the insert into tableB to fail when those conditions are not met. I have a feeling I'm missing something basic here
 
But you've posted a SELECT, not an INSERT. I'm a bit confused, sorry
 
Let me start over:
 
You can do an UPSERT (in name, it's actually ON CONFLICT DO) if you set a compound key across columns
 
9:25 PM
create tableA
(
a1 = int,
a2 = int,
)

create tableB
(
b1 = int references tableA(a1),
b2 = int,
magic
)

-- let's pretend I want someVal to be 3.2
insert into tableA(a1, a2) values (1.1, 1.2), (2.1,2.2), (3.1,3.2);
insert into tableB(b1, b2) values (1.1, 1) -- this should fail because in the row that contains a1=1.1, a2 is not 3.2
insert into tableB(b1, b2) values (3.3, 3.2); -- this should fail because a1 is never 3.3. The FK constraint fails
insert into tableB(b1, b2) values (3.1, 15); -- this should succeed because when a1 is 3.1, a2 is 3.2. The value of b2 is in fact irrelevant for thi
what should magic be, for this to happen?
 
so A is the fixed reference? That should never be changed in the query; it either exists and the insert should be done, or the insert should be ignored?
 
if a1 doesn't exist, the insert should be ignored. This part is correct
if a1 does exist, another check needs to be performed on a2. If this second check fails, the insert should be ignored
but if the second check also succeeds, the insert should be done
 
Ok, I'll have to think about that one sorry
 
all good. Thanks for trying. It's not trivial in the least
 
@inspectorG4dget I don't understand this part, though. Why should it be inserted on the basis of a2 when the a1 key doesn't exist?
 
9:38 PM
@roganjosh he said "if a1 does exist"
Or am I misunderstanding you?
 
@AndrasDeak you got it right
> if a1 doesn't exist, the insert should be ignored
 
Yep, sorry, I've got it now
 
all good. It's weird problem
 
10:12 PM
Ho
Hi
can I ask some question on mypy errors?
 
No need to ask if you can ask. Just go for it. If someone can answer, they will
 
@A.Man you should know this ^ by now
 
ok :)
so I have some block of code
and I'm getting some mypy errors
 
In case you missed it: here are our rules (cc @arielma)
@A.Man Sorry, that's too much to paste into chat directly. Please dump it into a code paste site or a github gist and link that here.
 
@A.Man That's... a lot of code. Can you put that into a dpaste please? dpaste.com And share the link here.
 
10:18 PM
sure
 
Also, if you haven't already, might be worth opening a question on the main site. More mypy eyes will be watching there. Make sure your question meets our posting guidelines though (minimal example, error traceback etc etc).
 
but you don't have to, coldspeed's just being eager with the suggestions
 
who is coldspeed
huehue
 
Ah, you just want to answer it to finally get swag rep. Makes sense.
 
Not really.
1) I don't know a single thing about mypy. 2) I haven't answered questions in nearly a week (tbh I have you to thank for that) and 3) I can get it either way without having to answer A. Man's question
 
10:22 PM
\o/
I agree with 3) though, you probably get that rep passively in a day or two
 
Right. FWIW for all our past disagreements I still respect you quite a bit especially because you supported me with the stalker crap happening. I just wish the feeling was mutual
 
Oh I respect you, just don't agree with some of your choices every now and then :P
but that shouldn't keep you up at night, I disagree with a lot of things
 
Ah, well that's progress I'm happy to hear, cheers :-)
ideal state is usually achieved in vacuum, but I can try getting close
 
@A.Man glanced at the removed text, there's a lot of errors here that are generally self-explanatory, can you ask a more pointed question about them (after you add them with dpaste or a gist or similar)?
E.g. your default project_design is None but you call .list_exported_bundles() on it without checking if it's not None first. Naturally, that's an error. But also you say the type of the variable is a list....and list_exported_bundles() is, of course, not a method on a list...so your type annotation is wrong. Also the project design argument is not listed in the docstring.
 
10:37 PM
ok tnx. I will check it
what about that:
`
    update_version = version.Version(
            f"{update_version.major}."
            f"{update_version.minor}."
            f"{update_version.micro + 1}"
        )
`
`
app_dss_bundle\bundles\export_bundle.py:96: error: "_BaseVersion" has no attribute "major"
app_dss_bundle\bundles\export_bundle.py:96: error: "_BaseVersion" has no attribute "minor"
app_dss_bundle\bundles\export_bundle.py:96: error: "_BaseVersion" has no attribute "micro"
`
any idea what this is about?
 
you don't have to add those backticks...
 
backticks means?
 
that thing you put around your code blocks here in chat
those only work (and are only necessary) for code in a single-line message
 
oh ok :)
 
How do you create the version which gets passed into that function? I'm not sure entirely based on what you've provided, but as an FYI, version.parse creates either a Version or a LegacyVersion. Both inherit from _BaseVersion and the base and legacy classes do not have major, minor, micro attributes. My guess is you are passing in something which could potentially give you a legacy version instead, so you'd have to cast or assert or check that it is not a legacy version.
before using those attributes. (assuming this is packaging.version.Version)
 
10:52 PM
ham... ok
how it decides what to choose? ersion or a LegacyVersion ?
Version or a LegacyVersion. based on what?
 
@cs95 Sounds like some French avant-garde film title...
 
@A.Man based on the version string...PEP 440 defined specific syntax for versioning, and a Version is one that meets that criteria, a legacy version does not meet that criteria.
 
ok tnx. I will check it
actually I'm using Version.parse instead of using try
 
Hello
 
I thought this way I can catch also exception, and make the string as Version
 
10:58 PM
Does anyone has experience regarding Selenium + Celery?
 
@ThomasAMET sorry, I missed it the first time you asked. We request that you don't ask for help with fresh questions on the main site as per our rules
 
Your type annotations don't clearly show that though. if you do parsed = version.parse() the resulting type is a union of version and legacy version type. if you don't want to handle the legacy version, you need to be explicit about it (e.g. assert not isinstance(v, version.LegacyVersion) or some other check in your code)
 
@AndrasDeak ok got it. What should I do then, I did not received any answer on the main site so and I am on that issue since 3 days already
Thanks for the message though
 
@smci not sure if I should be flattered, or offended :p
 
@ThomasAMET the usual mistake is using the wrong tag, but you seem to be covered there. Not sure you can do anything other than wait a bit more. If tomorrow you still don't get an answer you're welcome to link it here :)
The issue might be that you posted it on a weekend, when activity is low all across Stack Overflow.
 
11:04 PM
All right then! Thank you for heads up and wish you all a good night (1 am here).
Did not think about the weekend/weekday trafic ;) good catch
 
I thought you were in the Netherlands
In any case, good night
 
@AndrasDeak, I moved away and did not update my profile :). Take care
 
I see :) Bye
 
@Marco Sorry that'w way too broad. Do some profiling, figure out what your slowest task is, then give us one single specific case with code and sample data.
 
11:24 PM
@smci ok, alright, I will do it. Thanks!
Hello everyone! What would be the simplest type of plot considering complex numbers? It would not serve the Argaund-Gauss Plan.
Imagine a simple 2D plot (x and y axes), where I have on the x axis a range from 1 to 1000 and on the y axis a real number associated with the x axis. But if I have a complex number as y-axis values, what would be the simplest and most intuitive way for me to represent this graph?
 

« first day (3740 days earlier)      last day (1224 days later) »