« first day (3515 days earlier)      last day (1432 days later) » 

2:05 AM
I'm proposing to add this to the canon: How to check if a string in Python is in ASCII? Any comments? (Currently the only hit for 'ASCII' is How do I use non-ASCII strings in my Python script?)
@JonClements Yes could you go ahead and give me edit permission on canon?
@roganjosh Ok rj I started looking at the 294 pandas Q&A on drop_duplicates duplicated, here are my first thoughts...
Hmm, since a large part of the confusion is all the activity in 10 years of pandas versions adding features that handle duplicates () I guess the first thing would be a meta-Q&A (but this isn't really allowed on SO) on the history of pandas versions adding support for pd.Series.duplicated(), drop_duplicates(), nunique(), unique()..., also pd.DF.drop_duplicates . And there's also functionality wrt duplicates on .insert, nlargest/nsmallest, pivot_table (vs pivot), reorder_levels, set_index.
Sigh... don't know what to do about that. That's too broad to put on SO, and I'm not going to write an essay for the canon.
typo/irreproducible/trivial. OP was doing df.drop_duplicates(..., inplace=True) then wondering why they couldn;t assign the result. Retitled and edited for clarity. Why doesn't pandas drop_duplicates() seem to work for me?
This one might be worthy of canon: How do I get a list of all the duplicate items using pandas in python?. But that question is only about "duplicates in a single column (ID)", not "rows identical in multiple or all columns".
Ok what do we do with a question asked in two parts? from Oct 2019. part 1 + part 2. Part 2 has 2 answers, part 1 has none. Do we close part 1 into part 2?
typo/irrepro Duplicates, drop_duplicates malfunction. OP was not using keep=False
Needs more details, also no MCVE stackoverflow.com/questions/58390928/…
(Note to self: this one might be a duplicate, but still haven't determined of what)
 
3:10 AM
(This one is also a duplicate, haven't determined of what yet:
 
 
3 hours later…
6:29 AM
Hello! Anyone willing to help me?
I have a code in Python that goes like this
R_demand = [d for a, d in zip(J, R) if a in O]

but the conditional part of this comprehension list
only works if it is iterable, at certain part of my code
O may contain just an integer, thus error occur. Is there a way
where I can generelize the conditional part for both list(iterable)
and a single integer?
 
6:48 AM
@Acee if isinstance(O, int): O = [O]
 
7:28 AM
@Aran-Fey should I change the if a in O to if isinstance(O, int): ... ?
 
No, you should put that if before your list comprehension
 
@Acee Better: if not isinstance(O, list): O = [O] . This doesn't assume O must be any particular builtin type (int, float, string, boolean etc.). Of course it won't detect a tuple.
@Acee Also, it's not Pythonic to use uppercase in variable names: R, J, O. Always lower_case_with_underscores
 
@Aran-Fey thank you! will try running the code in a while
@smci thank you! Will take note of your comment
@Aran-Fey I tried running the code as follows:
if isinstance(o, int):
o = [o]
r_demand = [d for a, d in zip(J_set, R_int) if a in o]
print(r_demand)

but I keep getting the same error
 
7:45 AM
looks correct to me though
 
7:56 AM
@Aran-Fey thank you!! seems to be a fault in my indention. code works perfectly!
 
8:30 AM
@Acee That's why when you post code here, always use Code formatting so it show the indentation. See the Code formatting guide linked at the top right. (And experiment in the sandbox, esp. for multiline posts)
Re the MCVE for the boardgame-design calculations I discussed back on May 17, I'd like to get people's advice but I think the CSSA 4.0 forced relicensing is a show-stopper to posting it here.
 
 
1 hour later…
9:56 AM
@PM2Ring Yes, thanks for your reply. I am finally doing it with pillow.
 
 
1 hour later…
11:20 AM
 
@ChrisP this is the first time you're posting that here...
I don't use tkinter but your question is unclear. And it's not obvious if the linked answer helped you, and why not.
 
 
1 hour later…
1:07 PM
The pattern r'(?:0{2}|\+)(\d{2}) (\d{2}) (\d{6})|(\d{2}) (\d{6})' matches 34 567890 but I can't get any groups. How that can happen?
 
@AjayMishra please show the code with which you "can't get any groups". MCVE.
 
num =  '34 567890'
p = re.match(r'(?:0{2}|\+)(\d{2}) (\d{2}) (\d{6})|(\d{2}) (\d{6})', num)
print(p.group(1))
=> None
 
>>> p.groups()
(None, None, None, '34', '567890')
 
Wow.
Seems like both sides of | is matched?
 
Not matched, but included in the numbering of groups, apparently. I don't know re this well, so I'd read the docs carefully at this point if I were you.
 
1:10 PM
I am reading that.
 
putting a | in your regex doesn't reset the group number counter
you'll probably want to define your regex as (?:(?:00|\+)(\d{2}) )?(\d{2}) (\d{6}) instead
 
I tried that, perhaps I was missing something.
 
group 1 is optional there. The one you'd want to access is group 2
 
I guess I should try something else if my pattern would have been something like: p = re.match(r'(?:0{2}|\+)(\d{2}) (\d{2}) (\d{6})|(\d{3}) (\d{6})', num)(Please note that part after | is not a subset of before |)
 
1:26 PM
then you'll likely want two separate regexes
no, match the string against them one by one
 
oh, I see.But I am not allowed to do that, :D
 
Code challenge?
 
Yes.
 
...
 
This time, I think, it is constructive.
 
1:30 PM
obviously
"I'm not allowed to use the obvious solution" is the constructivliest
 
 
1 hour later…
2:58 PM
@smci I think that's fine for canon. If you're considering adding this to sopy then multiple targets could be added, in which case you could add this
@smci I wouldn't be happy to close part 1 into part 2, even if there is some crossover in root cause. It's simply not obvious that the questions are connected to me in the way I use SO, so I find that confusing.
 
 
2 hours later…
closed
 
Thanks :)
 
I have an app deployed on heroku , it works on local but crashes when I deploy it and I am unable to understand what the issue is, tried various SO answers yet no solution . Need help
heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=abc.herokuapp.com request_id=c03ade10-e3e5-48cf-931a-ce829a566d64 fwd="ip address" dyno= connect= service= status=503 bytes= protocol=https
That is the last message at error log
To an extent it means that there are no dynos running but i even tried doing heroku ps:scale and it did not work too
 
6:04 PM
that looks suspiciously not like a Python error. Did you check what error your application is reporting?
 
At some point I need to play with Heroku. The python error will be that their Flask (IIRC but maybe Django) app was never launched.
Well, I say will be, but I'm still guessing on that one too. I've seen it a number of times on the Flask tag
@AshwinPhadke Something like this?
There's another here that might be useful, which uses gunicorn but not Flask. The deployment process is somewhat alien to me
 
6:30 PM
needs focus (plz code, code, code) stackoverflow.com/questions/62120574/…
 
6:53 PM
Ew
I'm worried that this is not homework, but something job-related...
 
That applies to several questions I've seen over the years...
 
7:17 PM
NumPy question: How can i expand rows of a 2d-array for multiplication with a 1d-array?
More concretely, is there a way to combine the last three lines here into one expression?
n, u1, u2, u3 = np.arange(100), np.array([1, 0, -1]), np.array([2, -1, 6]), np.array([3, 0, 4])
x = -4*u1[0]*np.power(-0.4, n) + 3*u2[0]*np.power(0.5, n) + 2*u3[0]
y = -4*u1[1]*np.power(-0.4, n) + 3*u2[1]*np.power(0.5, n) + 2*u3[1]
z = -4*u1[2]*np.power(-0.4, n) + 3*u2[2]*np.power(0.5, n) + 2*u3[2]
 
are you worried about performance or do you just want to avoid code duplication?
 
I just want to avoid the duplication and learn more Numpy
Originally I thought numpy would maybe just broadcast each of the u vectors to have "width" 100, but I guess that's not how broadcasting works?
 
Not a numpy pwoer user. If performance is not an issue (it won't be slower than what you have right now), consider to use a loop for it.
 
That doesn't teach me any more NumPy, though :)
 
x, y, z = (-4*u1[i]*np.power(-0.4, n) + 3*u2[i]*np.power(0.5, n) + 2*u3[i] for i in range(3))
 
7:37 PM
are you looking for the outer product perhaps?
 
you just need broadcasting
@totokaka it can do that but you must help it
>>> x = -4*u1[0]*np.power(-0.4, n) + 3*u2[0]*np.power(0.5, n) + 2*u3[0]
... y = -4*u1[1]*np.power(-0.4, n) + 3*u2[1]*np.power(0.5, n) + 2*u3[1]
... z = -4*u1[2]*np.power(-0.4, n) + 3*u2[2]*np.power(0.5, n) + 2*u3[2]
...
... arr = np.array([u1, u2, u3])[..., None] # shape (3, n, 1)
... coeffs = np.array([-4, 3, 2])[:, None, None] # shape (3, 1, 1)
... powers = np.array([-0.4, 0.5, 1])[:, None, None] ** n # shape (3, 1, m)
... xyz = (coeffs * arr * powers).sum(0)  # shape (n, m)
... np.array_equal(xyz, [x, y, z])
it can probably be done with less work but I was too lazy to write it out on paper
and it would be better style to have the summation axis last, that's usually (but not always) faster
 
outer product seems to be what I want!
 
you can probably also matmul it
 
thought so too, didn't work out of the box :/
 
x = -4*np.outer(u1, np.power(-0.4, n)) + \
    3*np.outer(u2, np.power(0.5, n)) + \
    2*np.outer(u3, np.ones(100))
That worked
 
7:49 PM
you don't need \ in parenthesees, and they look bad
 
This is not in parens :)
 
Ah, sorry. Then put parentheses around it :P
 
Ahh, thanks, I agree putting parens around is nicer
So now the question is how to avoid the outer product with the ones
With some inspiration from you, Andras, I got this
x = (-4*np.outer(u1, np.power(-0.4, n)) +
      3*np.outer(u2, np.power(0.5, n)) +
      2*u3[:,None])
 
we could make it both more fun and confusing with einsum
 
I prefer to make it simpler ;p
u1 = np.array([[1], [0], [-1]])
u2 = np.array([[2], [-1],[6]])
u3 = np.array([[3], [0], [4]])
n = np.arange(100)
x = -4*u1*np.power(-0.4, n) + 3*u2*np.power(0.5, n) + 2*u3
 
8:01 PM
np.einsum('i,j', u1, np.power(-0.4, n)) seems pretty tame, actually
 
that's just a single term, and unnecessary instead of outer
 
it reminds me of the warm and fuzzy feeling I had when solving homework in theoretical physics, though.
 
>>> arr = np.array([u1, u2, u3])  # shape (3, 3)
... coeffs = np.array([-4, 3, 2])  # shape (3, )
... powers = np.array([-0.4, 0.5, 1])[:, None] ** n  # shape (3, n)
... xyz2 = np.einsum('i,in,it->tn', coeffs, powers, arr)
...
... np.array_equal(xyz, xyz2)
True
 
Thanks for the help, guys
 
anytime
that einsum does suggest that we could write this as a matmul, though
slap the coefficients on either arr or powers, transpose the definition of one of them, and then shape (3, 3) @ shape (3, n)
 
8:22 PM
Is there a way by which I can save the execution of a Jupyter notebook and start the execution from the saved point?
 
@RoshinRaphel I'm not a jupyter user but stackoverflow.com/questions/34342155/… was the first google hit
it's reasonable that it can't be done in the general case but it can be done in a lot of cases
 
Let me check
 
Are you sure you need to store the entire session?
Caching only some expensive-to-make objects may be more well-behaved.
 
9:24 PM
Anyone know of a Flask Q&A that clearly demonstrates why you need url_for? The closest I can find is this answer but it doesn't show anything going kaboom
 
10:14 PM
How do I check if a subtring is strictly in string?
 
Strictly?
==? Otherwise I don't understand the question.
Or you mean not on the edge? subs in s[1:-1] perhaps
need for MCVE intensifies
 
['\r\n\t\t\t\t\t\t\t', '\n', '\ntext, '\n', '\nmytext\r\n\t\t\t\t\t\t'] I would everything except the first element.
 
That doesn't help one bit.
 
The above signifies a post on a forum. The last part with six tabs signifies the end. That's the real problem, is getting the index elements where the post ends.
 
Mhmm.
 
10:23 PM
You've added context, but you haven't explained anything
 
I get the right indexes but I also get the wrong indexes, namely the start of the posts with the seven tabs. And the start of posts can also can start with six tabs, but only if there's content.
 
What indices are we talking about and which ones of them are the right ones?
 
If I search for \r\n\t\t\t\t\t\t I get the start of posts as well because this is included in the one with seven tabs
those are the wrong ones
\r\n\t\t\t\t\t\t\tmytext\r\n\t\t\t\t\t\t' is read as the end of a post, which is good - but something like \r\n\t\t\t\t\t\t\twronganswer is also read as the end of a post but it's not
correct\r\n\t\t\t\t\t\t is correct and what i need
 
so basically you're trying to find exactly 6 consecutive tabs, but not 7?
 
Not exactly
As I said...six tabs can signify the start of a post too
but the six tabs at the end signifies the correct answer
the wrong answer MCVE above is the start of a post
 
10:34 PM
I don't understand how you tell apart the start and the end, then
 
the-right-signifies-the-end-everytime\r\n\t\t\t\t\t\t
blablabla\r\n\t\t\t\t\t\t
but not \r\n\t\t\t\t\t\t\ttblablabla
 
ok, then you'll want regex: \w\r\n\t{6}(?!\t)
 
10:48 PM
That doesn't match '\r\n\t\t\t\t\t\t\talso-correct\r\n\t\t\t\t\t\t' but we are onto something.
if \w\r\n\t{6} is preceded by text, it's correct
 
Wait, are you applying the regex to those list elements?
 
Yes
Using a for loop
 
Then surely you can just do if list_element.endswith('\r\n\t\t\t\t\t\t'):?
 
I didn't know that existed
¯_(ツ)_/¯
Thanks
It's pretty interesting to know a solution can exist with regex, however. I'll consider it next time.
 

« first day (3515 days earlier)      last day (1432 days later) »