[docs]classEmailAddressToDomain(TransformPrimitive):"""Determines the domain of an email Description: EmailAddress input should be a string. Will return Nan if an invalid email address is provided, or if the input is not a string. Examples: >>> email_address_to_domain = EmailAddressToDomain() >>> email_address_to_domain(['name@gmail.com', 'name@featuretools.com']).tolist() ['gmail.com', 'featuretools.com'] """name="email_address_to_domain"input_types=[ColumnSchema(logical_type=EmailAddress)]return_type=ColumnSchema(logical_type=Categorical,semantic_tags={"category"})defget_function(self):defemail_address_to_domain(emails):# if the input is empty return an empty Seriesiflen(emails)==0:returnpd.Series([],dtype="category")emails_df=pd.DataFrame({"email":emails})# if all emails are NaN expand won't propogate NaNs and will fail on indexingifemails_df["email"].isnull().all():emails_df["domain"]=np.nanemails_df["domain"]=emails_df["domain"].astype(object)else:# .str.strip() and .str.split() return NaN for NaN values and propogate NaNs into new columnsemails_df["domain"]=(emails_df["email"].str.strip().str.split("@",expand=True)[1])returnemails_df.domain.valuesreturnemail_address_to_domain