I have problem at my code.
This is part of __init__:
file = np.loadtxt(file_path,delimiter = ",",skiprows=1)
header = np.loadtxt(file_path,delimiter = ",",dtype=str)
self.data = file
self.header = header[0]
This is part of a method:
def hello(self,col_name)
col = self.header.where[a == col_name]
return col
Then I wanted to check if I get the index of the header:
print (name.hello('hi'))
but got: "AttributeError: 'numpy.ndarray' object has no attribute 'where'"
Related
I'm trying to add try and except to my code but it does not work.
def _get_table_df(self, table):
l = module.send_command(name='Read', attributes={'type': table, 'method':'all', 'limit':'1', 'enable_custom':1})
so = BeautifulSoup(l.text,'xml')
columns = []
try:
for x in list(so.find(table).children):
columns.append(x.name)
df = pd.DataFrame(columns=columns)
except AttributeError:
return "no data"
return df
The error pointing to try line says
AttributeError: 'NoneType' object has no attribute 'children'
I am trying to mock "ConfigFactory.parse_file" for unit testing purpose and getting the following error.
AttributeError: 'str' object has no attribute 'as_plain_ordered_dict'
I tried mocking the attribute as_plain_ordered_dict to resolve the issue, but still getting the same error.
class Testt2StatsExporter(unittest.TestCase):
#patch('t2.client.OverlayClient')
#patch('pyhocon.ConfigFactory.parse_file')
#patch('oci.auth.signers.instance_principals_security_token_signer.InstancePrincipalsSecurityTokenSigner')
def test_create_telemetry_client(self, mock_config_factory, mock_security_token_signer, mock_client):
test_config = Mock()
test_config.json.return_value = {'metricsConfig': 'test_config'}
path_to_local_config = Mock()
type(path_to_local_config).as_plain_ordered_dict = PropertyMock(return_value=test_config)
mock_security_token_signer.return_value = "test_token"
mock_config_factory.return_value = test_config
mock_client.return_value = True
self.assertEqual(True, _create_telemetry_client(path_to_local_config))
and here is the main code base that I am testing.
path_to_local_config = '/etc/dlp/t2_config.conf'
def _create_telemetry_client(path_to_local_config: str):
t2config = ConfigFactory.parse_file(path_to_local_config).as_plain_ordered_dict()
common_config = t2config['metricsConfig']
t2_client_config = {'metricsConfig': common_config}
auth_provider = InstancePrincipalsSecurityTokenSigner()
return client.OverlayClient(t2_client_config, authentication_provider=auth_provider)
What can I try next?
def fetchAndUpdateAllOrderDetails(self, orders):
fyers = self.brokerHandle
orderBook = None
try:
orderBook = fyers.orderbook()
except Exception as e:
logging.error('%s Failed to fetch order book', self.broker)
return
logging.info('%s Order book length = %d', self.broker, len(orderBook))
numOrdersUpdated = 0
for bOrder in orderBook:
foundOrder = None
for order in orders:
if order.orderId == bOrder['orderBook']['id']:
foundOrder = order
break
if foundOrder != None:
def fetchAndUpdateAllTradeOrders():
allOrders = []
for trade in TradeManager.trades:
if trade.entryOrder != None:
allOrders.append(trade.entryOrder)
if trade.slOrder != None:
allOrders.append(trade.slOrder)
if trade.targetOrder != None:
allOrders.append(trade.targetOrder)
TradeManager.getOrderManager().fetchAndUpdateAllOrderDetails(orders = allOrders)
It returns the error:
Traceback (most recent call last):
File "d:\AlgoTraderFyers\src\trademgmt\TradeManager.py", line 76, in run
TradeManager.fetchAndUpdateAllTradeOrders()
File "d:\AlgoTraderFyers\src\trademgmt\TradeManager.py", line 227, in fetchAndUpdateAllTradeOrders
TradeManager.getOrderManager().fetchAndUpdateAllOrderDetails(orders = allOrders)
AttributeError: 'NoneType' object has no attribute 'fetchAndUpdateAllOrderDetails'
It was working with the other broker(zerodha). Pls help!
AttributeError: 'NoneType' object has no attribute 'fetchAndUpdateAllOrderDetails'
This means that the thing you are calling the fetchAndUpdateAllOrderDetails() function on is "None".
So in this case, the return value of TradeManager.getOrderManager() is None.
Are you returning anything from the getOrderManager() function?
I'm aware that there are similar problems to mine but I tried those solutions and they don't work.
I have text field:
self.tMail = QtGui.QPlainTextEdit(self.centralwidget)
self.tMail.setGeometry(QtCore.QRect(50, 270, 451, 75))
self.tMail.setAccessibleName(_fromUtf8(""))
self.tMail.setInputMethodHints(QtCore.Qt.ImhNone)
self.tMail.setPlainText(_fromUtf8(""))
self.tMail.setOverwriteMode(False)
self.tMail.setObjectName(_fromUtf8("tMail"))
And i want to add them to the variable string by:
def handleButton(self):
timeString = self.tCzas.text()
mailString = self.tMail.text()
IDString = self.tID.text()
teamString = self.tTeam.text()
print(timeString)
print(mailString)
print(IDString)
print(teamString)`
also I tried:
mailString = self.tMail.plainText()
and I always get an error:
AttributeError: 'QPlainTextEdit' object has no attribute '...'
Why?
QPlainTextEdit doesn't have a text() function. try using the toPlainText() function:
def handleButton(self):
timeString = self.tCzas.toPlainText()
mailString = self.tMail.toPlainText()
IDString = self.tID.toPlainText()
teamString = self.tTeam.toPlainText()
print(timeString)
print(mailString)
print(IDString)
print(teamString)
I am trying to create a malware classifier and I am experiencing the error
AttributeError: 'Series' object has no attribute 'Id. Not sure of the error.
Traceback (most recent call last):
File"C:/Users/Afiqmatters/PycharmProjects/MajorProject/feature_extraction.py", line 23, in <module>
rids = [mids.loc[i].Id for i in rchoice]
File "C:\Users\Afiqmatters\Miniconda\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'Id'
Here is the codes I have up to the error.
rs = Random()
rs.seed(1)
trainLabels = pd.read_csv('trainLabels.csv')
#print trainLabels
fids = []
opd = pd.DataFrame()
for label in range(1,10):
mids = trainLabels[trainLabels.Class == label]
mids = mids.reset_index(drop=True)
#print mids
rchoice = [rs.randint(0, len(mids) - 1) for i in range(10)]
print len
#print rchoice
rids = [mids.loc[i].Id for i in rchoice]
The error happens at rids = [mids.loc[i].Id for i in rchoice] and I am not sure of the error.
A sample of what is stored in the trainLabels.csv
Id Class
0A32eTdBKayjCWhZqDOQ 2
mids.loc[i] in this context is a "Series" object which is detailed here
This object type does not have an attribute Series.Id, so that's why you're seeing this error.
Did you mean to call the built-in function id( ) on the object?
rids = [id(mids.loc[i]) for i in rchoice]