I am using vim + vim-airline, and it looks like this in my terminal:
as you can see, it just shows a bit of the warnings, is this intended?
It will show more if I lengthen the window, but how can I set it to show the full warning messages for the current window size? for example, if I can adjust the section width or do something else?
In my .vimrc I have
28 set laststatus=2
27 let g:airline_powerline_fonts = 1
26 let g:airline_theme='luna'
25 let g:airline#extensions#default#section_truncate_width = {
24 \ 'b': 79,
23 \ 'x': 60,
22 \ 'y': 50,
21 \ 'z': 45,
20 \ 'warning': 12,
19 \ 'error': 80,
18 \ }
You can use :CocList diagnostics to list all diagnostics, if you have installed coc.nvim plugin. Or you can check the 55 line in your file. You also can diasable it by "let g:airline_section_error = ''.
Related
I'm 63 and just started with Python (My first steps with Udemy).
I'm Croatian so this is croatian language in program but you will understand when you run a program. I know it can be cleaner, shorter, more elegant etc, but as I mentioned before - I'm beginner.
import random
jedan = random.sample(range(1,99),15)
dva = random.sample(range(1,99),15)
def raspaljot(jedan, dva, i):
for x in jedan:
for y in dva:
if y == x:
index1 = jedan.index(x)
index1_str = str(index1)
index2 = dva.index(y)
index2_str = str(index2)
i += 1
x = str(x)
print(" Broj \033[31m" + x + "\033[0m,je dupli i nalazi se u listi jedan: na poziciji: \033[34m"
+ index1_str + "\033[0m a u listi dva na poziciji: \033[35m"+ index2_str + "\033[0m")
print()
print(jedan)
print(dva)
if i != 0:
print("\n *** Ukupno ima ", i, 'duplih brojeva. ***')
elif i == 0:
print("Nema duplih brojeva. :) ")
i = 0
raspaljot(jedan, dva,i)
What program do is finding duplicates in 2 random lists, them print duplicates in color and detecting position inside list[1] and list[2].
What I trying to do is printing list1 and list2 but showing duplicates in color.
For example:
[14, 78, 85, 31, 5, 54, 13, 46, 83, 4, 35, 41, 52, 51, 32]
[72, 40, 67, 85, 54, 76, 77, 39, 51, 36, 91, 70, 71, 38, 55]
here we have 3 duplicates (85,54,51). This above example on the console End was printed in white color, but I wanna these 3 numbers in red color in those two lines above.
Is this possible? I couldn't find a solution.
PS. Wing Pro version 7 on Fedora 33 Workstation / In WIngIde colors are only displayed in an external console and not the Debug I/O tool. :)
Simple solution would be something like this:
# Change list to string
jedan_str = str(jedan)
# Create set with numbers that need new color
num_set = {"85", "54", "51"}
# Iterate over every number and wrap it with color change
for i in num_set:
# Note that I used f-string to format string
# But you can also do this as "\033[31m" + i + "\033[0m"
jedan_str = jedan_str.replace("85", f"\033[31m{i}\033[0m")
# Print string that represent list
print(jedan_str)
Following the idea of using a set to determine which elements are in both lists (as Cv4niak proposed in his answer), I created a function to print the output as you desire. There are numerous other ways of achieving it, but I think this is a simple yet effective way.
The idea is to use the cprint() function from the termcolor package. You can install it with pip install termcolor, and then print normally all elements, except the ones that are duplicates, which will be printed using cprint(item, "red").
The "{:0>2d}" formatting in each ìtem print serves only to pad the number with zeros (so 2 will be printed as 02, for example), in order for the output of both lists to be aligned.
import random
from termcolor import cprint
def mark_duplicates(first, second):
duplicates = list(set(first).intersection(second))
if duplicates:
for list_ in [first, second]:
print("[", end="")
for item in list_:
if item in duplicates:
cprint("{:0>2d}".format(item), "red", end=",")
else:
print("{:0>2d}".format(item), end=",")
print("\b]")
else:
print("No duplicates.")
jedan = random.sample(range(1, 99), 15)
dva = random.sample(range(1, 99), 15)
mark_duplicates(jedan, dva)
With this, if there are no duplicates, the No duplicates. string will be printed. Also you can change the color with not much effort, and use other nice functionalities from termcolor package.
this is part of my code.it reads from an excel file.
I'm getting a type error saying "TypeError: sequence item 0: expected str instance, list found".
text=df.loc[page,["rev"]]
def remove_punct(text):
text=''.join([ch for ch in text if ch not in exclude])
tokens = re.split('\W+', text),
tex = " ".join([word for word in tokens if word not in cachedStopWords]),
return tex
s=df.loc[page,["rev"]].apply(lambda x:remove_punct(x))
this is the error.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-16-4f3c29307e88> in <module>()
26 return tokens
27
---> 28 s=df.loc[page,["rev"]].apply(lambda x:remove_punct(x))
29
30 with open('FileName.csv', 'a', encoding="utf-8") as f:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
3190 else:
3191 values = self.astype(object).values
-> 3192 mapped = lib.map_infer(values, f, convert=convert_dtype)
3193
3194 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src\inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-16-4f3c29307e88> in <lambda>(x)
26 return tokens
27
---> 28 s=df.loc[page,["rev"]].apply(lambda x:remove_punct(x))
29
30 with open('FileName.csv', 'a', encoding="utf-8") as f:
<ipython-input-16-4f3c29307e88> in remove_punct(text)
23 text=''.join([ch for ch in text if ch not in exclude])
24 tokens = re.split('\W+', text),
---> 25 tex = " ".join([ch for ch in tokens if ch not in cachedStopWords]),
26 return tokens
27
TypeError: sequence item 0: expected str instance, list found
I think the commas at the end of these two lines create a list of the variables you are trying to process.
tokens = re.split('\W+', text), # <---- These commas at the end
tex = " ".join([word for word in tokens if word not in cachedStopWords]), # <----
It would result in roughly the same as if you did something like this (edited for better example):
x = 12 * 24,
y = x * 10,
z = 40
print(f"X = {x}\n"
f"Y = {y}\n"
f"Z = {z}\n")
Output:
X = (288,)
Y = ((288, 288, 288, 288, 288, 288, 288, 288, 288, 288),)
Z = 40
The commas result in packing and unpacking of your variables.
I need to iterate over column 'movies_rated', check the value against the conditions, and write a value in a newly create column 'expert_level'. When I test on a subset of data, it works. But when I run it against my whole dateset, it only gets filled with value 1.
for num in df_merge['movies_rated']:
if num in range(20,31):
df_merge['expert_level'] = 1
elif num in range(31,53):
df_merge['expert_level'] = 2
elif num in range(53,99):
df_merge['expert_level'] = 3
elif num in range(99,202):
df_merge['expert_level'] = 4
else:
df_merge['expert_level'] = 5
here's a sample dataframe.
movies = [88,20,35,55,1203,99,2222,847]
name = ['angie','chris','pine','benedict','alice','spock','tony','xena']
df = pd.DataFrame(movies,name,columns=['movies_rated'])
certainly there's a less verbose way of doing this?
You could build an IntervalIndex and then apply pd.cut. I'm sure this is a duplicate, but I can't find one right now which uses both closed='left' and .codes, though I'm sure it exists.
bins = pd.IntervalIndex.from_breaks([0, 20, 31, 53, 99, 202, np.inf], closed='left')
df["expert_level"] = pd.cut(movies, bins).codes
which gives me
In [242]: bins
Out[242]:
IntervalIndex([[0.0, 20.0), [20.0, 31.0), [31.0, 53.0), [53.0, 99.0), [99.0, 202.0), [202.0, inf)]
closed='left',
dtype='interval[float64]')
and
In [243]: df
Out[243]:
movies_rated expert_level
angie 88 3
chris 20 1
pine 35 2
benedict 55 3
alice 1203 5
spock 99 4
tony 2222 5
xena 847 5
Note that I've set this up so that scores below 20 get a 0 value, so they can be distinguished from really high rankings. If you really want everything outside the bins to get 5, it'd be straightforward to remap 0 to 5, or just pass breaks of [20, 31, 53, 99, 202] and then map anything with a code of -1 (which means 'not binned') to 5.
I think np.select with the pandas function between is a good choice for you:
conds = [df.movies_rated.between(20,30), df.movies_rated.between(31,52),
df.movies_rated.between(53,98), df.movies_rated.between(99,202)]
choices = [1,2,3,4]
df['expert_level'] = np.select(conds,choices, 5)
>>> df
movies_rated expert_level
angie 88 3
chris 20 1
pine 35 2
benedict 55 3
alice 1203 5
spock 99 4
tony 2222 5
xena 847 5
you could do it with apply and a function:
def expert_level_check(num):
if 20<= num < 31:
return 1
elif 31<= num < 53:
return 2
elif 53<= num < 99:
return 3
elif 99<= num < 202:
return 4
else:
return 5
df['expert_level'] = df['movies_rated'].apply(expert_level_check)
it is slower to manually iterate over a df, I recommend reading this
My input data has the following format
id offset code
1 3 21
1 3 24
1 5 21
2 1 84
3 5 57
3 5 21
3 5 92
3 10 83
3 10 21
I would like the output in the following format
id offset code
1 [3,5] [[21,24],[21]]
2 [1] [[84]]
3 [5,10] [[21,57,92],[21,83]]
The code that I have been able to come up with is shown below
import random, pandas
random.seed(10000)
param = dict(nrow=100, nid=10, noffset=8, ncode=100)
#param = dict(nrow=1000, nid=10, noffset=8, ncode=100)
#param = dict(nrow=100000, nid=1000, noffset=50, ncode=5000)
#param = dict(nrow=10000000, nid=10000, noffset=100, ncode=5000)
pd = pandas.DataFrame({
"id":random.choices(range(1,param["nid"]+1), k=param["nrow"]),
"offset":random.choices(range(param["noffset"]), k=param["nrow"])
})
pd["code"] = random.choices(range(param["ncode"]), k=param["nrow"])
pd = pd.sort_values(["id","offset","code"]).reset_index(drop=True)
tmp1 = pd.groupby(by=["id"])["offset"].apply(lambda x:list(set(x))).reset_index()
tmp2 = pd.groupby(by=["id","offset"])["code"].apply(lambda x:list(x)).reset_index().groupby(\
by=["id"], sort=True)["code"].apply(lambda x:list(x)).reset_index()
out = pandas.merge(tmp1, tmp2, on="id", sort=False)
It does give me the output that I want but is VERY slow when the dataframe is large. The dataframe that I have has over 40million rows. In the example
uncomment the fourth param statement and you will see how slow it is.
Can you please help with making this run faster?
(df.groupby(['id','offset']).code.apply(list).reset_index()
.groupby('id').agg(lambda x: x.tolist()))
Out[733]:
offset code
id
1 [3, 5] [[21, 24], [21]]
2 [1] [[84]]
3 [5, 10] [[57, 21, 92], [83, 21]]
ICU message formatting doesn't seem to work for me. Here's the example:
$n = 22;
$f = MessageFormatter::create('ru', '{n, plural, one{корова} few{коровы} many{коров} other{коров}}');
echo $n.' '.$f->format(['n' => $n])."\n";
I get 22 коров in output, but obviously should get 22 коровы. Tried on several ubuntu servers.
Language: Russian
php-intl version 1.1.0
ICU version 52.1
Any help will be appriciated, cause I stuck on it.
That's one nasty bug, one that I've spent almost hour figuring out. Well, it turns out in ICU 52.1 (probably before, too) we have the following:
set34{
many{
"v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100"
" = 11..14 #integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …"
}
one{
"v = 0 and i % 10 = 1 and i % 100 != 11 #integer 1, 21, 31, 41, 51, 6"
"1, 71, 81, 101, 1001, …"
}
other{
" #integer 2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, … #decimal"
" 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
}
}
Source: http://source.icu-project.org/repos/icu/icu/tags/release-52-1/source/data/misc/plurals.txt
So, cases of 2-4, 22-24 and so on (22 коровы) fall under other modifier, so the correct syntax for your case would be {n, plural, one{корова} few{коровы} many{коров} other{коровы}}. I left few in for compatibility with newer ICU versions (which indeed use few modifier for this case).