问:
Configure external jars with HDI Jupyter Spark (Scala) notebook
I have an external custom jar that I would like to use with Azure HDInsight Jupyter notebooks; the Jupyter notebooks in HDI use Spark Magic and Livy.

Within the first cell of the notebook, I'm trying to use the jars configuration:

```<code>%%configure -f
{"jars": ["wasb://$container$@$account#.blob.core.windows.net/folder/my-custom-jar.jar"]}
</code>```

But the error message I receive is:

```<code>Starting Spark application
The code failed because of a fatal error:
    Status 'shutting_down' not supported by session..

Some things to try:
a) Make sure Spark has enough available resources for Jupyter to create a Spark context. For instructions on how to assign resources see http://go.microsoft.com/fwlink/?LinkId=717038
b) Contact your cluster administrator to make sure the Spark magics library is configured correctly.
Current session configs: {u'jars': [u'wasb://$container$@$account#.blob.core.windows.net/folder/my-custom-jar.jar'], u'kind': 'spark'}
An error was encountered:
Status 'shutting_down' not supported by session.
</code>```

I'm wondering if I'm just not understanding how Livy works in this case  as I was able to successfully include a spark-package (GraphFrames) on the same cluster:

```<code>%%configure -f
{ "conf": {"spark.jars.packages": "graphframes:graphframes:0.3.0-spark2.0-s_2.11" }}
</code>```

Some additional references that may be handy (just in case I missed something):

Jupyter notebooks kernels with Apache Spark clusters in HDInsight

Livy Documentation

Submit Spark jobs remotely to an Apache Spark cluster on HDInsight using Livy

答:
Oh, I was able to figure it out and forgot to update my question. This can work if you put the jar in the default storage account of your HDI cluster.

HTH!

Body:
I have an external custom jar that I would like to use with Azure HDInsight Jupyter notebooks; the Jupyter notebooks in HDI use Spark Magic and Livy.

Within the first cell of the notebook, I'm trying to use the jars configuration:

%%configure -f
{"jars": ["wasb://$container$@$account#.blob.core.windows.net/folder/my-custom-jar.jar"]}

But the error message I receive is:

Starting Spark application
The code failed because of a fatal error:
    Status 'shutting_down' not supported by session..

Some things to try:
a) Make sure Spark has enough available resources for Jupyter to create a Spark context. For instructions on how to assign resources see http://go.microsoft.com/fwlink/?LinkId=717038
b) Contact your cluster administrator to make sure the Spark magics library is configured correctly.
Current session configs: {u'jars': [u'wasb://$container$@$account#.blob.core.windows.net/folder/my-custom-jar.jar'], u'kind': 'spark'}
An error was encountered:
Status 'shutting_down' not supported by session.

I'm wondering if I'm just not understanding how Livy works in this case  as I was able to successfully include a spark-package (GraphFrames) on the same cluster:

%%configure -f
{ "conf": {"spark.jars.packages": "graphframes:graphframes:0.3.0-spark2.0-s_2.11" }}

Some additional references that may be handy (just in case I missed something):

Jupyter notebooks kernels with Apache Spark clusters in HDInsight

Livy Documentation

Submit Spark jobs remotely to an Apache Spark cluster on HDInsight using Livy


来源: stackexchange

问:
How to install version from nexus with minor version
I have many version of my appliction in nexus with versions 1.52.0-xxxxx
the xxxx is different dates
I have also version of 1.53 and 1.54
How I can get the latest 1.52.0-with the latest date without get the 1.53 version and later
this is my package.json</p>

```<code> "name": "client-tests",
  "version": "0.0.1",
  "devDependencies": {
    "myApp":>="1.52.0".
}
</code>```

答:
Update answer

After getting more information in the comments and after the question got edited, I now see that you need to update the version of a Node package, not a version of Node itself as was asked originally.

To get the latest version of 1.52.x but not 1.53.x use:

```<code>"myApp": "1.52.x"
</code>```

in package.json. You could also do:

```<code>"myApp": ">=1.52.0 <1.53.0"
</code>```

or:

```<code>"myApp": "~1.52.0"
</code>```

See the documentation for more info:

https://docs.npmjs.com/files/package.json#dependencies

and the the documentation of the semver module for even more details:

https://docs.npmjs.com/misc/semver

Original answer

The latest version of Node is not 1.52 but 7.x and soon 8.0 will be released.

To see you re node version run:

```<code>node -v
</code>```

in the commend line, or test process.versions.node on the Node program.

To upgrade see those answers:

node 5.5.0 already installed but node -v fetches with "v4.2.1" on OS X & homebrew?

how to run node js on dedicated server?

Run npm as superuser, it isn't a good idea?

Install Node.js with downloaded binary on Ubuntu Desktop.. Where do the files go?

NPM and NODE command not found when using NVM

ContentLicense: CC BY-SA 3.0

Body:
I have many version of my appliction in nexus with versions 1.52.0-xxxxx
the xxxx is different dates
I have also version of 1.53 and 1.54
How I can get the latest 1.52.0-with the latest date without get the 1.53 version and later
this is my package.json

 "name": "client-tests",
  "version": "0.0.1",
  "devDependencies": {
    "myApp":>="1.52.0".
}

Body:
Update answer

After getting more information in the comments and after the question got edited, I now see that you need to update the version of a Node package, not a version of Node itself as was asked originally.

To get the latest version of 1.52.x but not 1.53.x use:

"myApp": "1.52.x"

in package.json. You could also do:

"myApp": ">=1.52.0 <1.53.0"

or:

"myApp": "~1.52.0"

See the documentation for more info:

https://docs.npmjs.com/files/package.json#dependencies

and the the documentation of the semver module for even more details:

https://docs.npmjs.com/misc/semver

Original answer

The latest version of Node is not 1.52 but 7.x and soon 8.0 will be released.

To see you re node version run:

node -v

in the commend line, or test process.versions.node on the Node program.

To upgrade see those answers:

node 5.5.0 already installed but node -v fetches with "v4.2.1" on OS X & homebrew?

how to run node js on dedicated server?

Run npm as superuser, it isn't a good idea?

Install Node.js with downloaded binary on Ubuntu Desktop.. Where do the files go?

NPM and NODE command not found when using NVM


问:
Properly unmount React component
Question: Why is this warning being thrown after the component is no longer being rendered by its parent? Am I missing something that needs to be done for unmounting of this component rather than just filtering the store state being passed down the hierarchy of components as props?

I've seen this scenario thrown around a lot, but the solution is usually something that involves unsubscribing the redux store from the component; however, this component is not connected to the store, just top-level container.

The remove action simply filters the store state to remove the array element responsible for the current component.

The refresh action is currently just a simulation for UI animation events in a child component.

Warning is only thrown when I remove a Feed component after calling the refresh action

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Feed component.

```<code>// @flow
// Feed.js

import React, { Component } from 'react'
import type { FeedType, FeedState } from '../../utils/types'
import { remove, refresh } from '../../actions/redux-actions'
import RssEventList from '../containers/RssEventList'

const cardColors: Array<string> = ['red', 'orange', 'olive', 'green', 'blue', 'yellow']

export default class Feed extends Component {
  props: FeedType
  state: FeedState

  constructor(props: *) {
    super(props)

    this.state = {
      reloading: false
    }
  }

  refresh() {
    this.setState({ reloading: true })
    setInterval(() => this.setState({ reloading: false }), 4000)
    this.props.dispatch(refresh(this.props.link))
  }

  remove() {
    this.props.dispatch(remove(this.props.link))
  }

  render() {
    const color: string = cardColors[Math.floor(Math.random() * cardColors.length)]

    return (
      <div className={`ui ${color} card`}>
        <div className="content">
          <div className="ui header">
            {this.props.title}
            <a className="source link" href={this.props.link} target="_blank">
              <i className="linkify right floated icon"></i>
            </a>
          </div>
          <div className="meta">
            {this.props.description}
          </div>
        </div>
        <div className="content">
          <RssEventList reloading={this.state.reloading} events={this.props.feed} />
        </div>
        <div className="extra content">
          <span className="left floated" onClick={() => this.refresh()}>
            <i className="refresh icon"></i>
            Refresh
          </span>
          <span className="right floated" onClick={() => this.remove()}>
            <i className="cancel icon"></i>
            Remove
          </span>
        </div>
      </div>
    )
  }
}
</code>```

If it helps, here is a diagram of the component hierarchy:

```<code>App (connected to store)
|- Header
|- FilterBar
|- FeedList
   |- Feed
      |- RssEventList
         |- RssEvent
   |- AddCard
</code>```

答:
The problem is that you are not storing your interval on component to remove it when component unmounts. Therefore, the interval will continue to be called even after the component is unmounted. You need to remove it with clearInterval():

```<code>export default class Feed extends Component {
  refresh() {
    this.myInterval = setInterval(() => this.setState({ reloading: false }), 4000)
  }

  componentWillUnmount() {
    clearInterval(this.myInterval);
  }
}
</code>```

Title: Properly unmount React component

Body:
Question: Why is this warning being thrown after the component is no longer being rendered by its parent? Am I missing something that needs to be done for unmounting of this component rather than just filtering the store state being passed down the hierarchy of components as props?

I've seen this scenario thrown around a lot, but the solution is usually something that involves unsubscribing the redux store from the component; however, this component is not connected to the store, just top-level container.

The remove action simply filters the store state to remove the array element responsible for the current component.

The refresh action is currently just a simulation for UI animation events in a child component.

Warning is only thrown when I remove a Feed component after calling the refresh action

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Feed component.

// @flow
// Feed.js

import React, { Component } from 'react'
import type { FeedType, FeedState } from '../../utils/types'
import { remove, refresh } from '../../actions/redux-actions'
import RssEventList from '../containers/RssEventList'

const cardColors: Array<string> = ['red', 'orange', 'olive', 'green', 'blue', 'yellow']

export default class Feed extends Component {
  props: FeedType
  state: FeedState

  constructor(props: *) {
    super(props)

    this.state = {
      reloading: false
    }
  }

  refresh() {
    this.setState({ reloading: true })
    setInterval(() => this.setState({ reloading: false }), 4000)
    this.props.dispatch(refresh(this.props.link))
  }

  remove() {
    this.props.dispatch(remove(this.props.link))
  }

  render() {
    const color: string = cardColors[Math.floor(Math.random() * cardColors.length)]

    return (
      <div className={`ui ${color} card`}>

            {this.props.title}

            {this.props.description}

          <RssEventList reloading={this.state.reloading} events={this.props.feed} />

           this.refresh()}>

            Refresh

           this.remove()}>

            Remove

    )
  }
}

If it helps, here is a diagram of the component hierarchy:

App (connected to store)
|- Header
|- FilterBar
|- FeedList
   |- Feed
      |- RssEventList
         |- RssEvent
   |- AddCard

Body:
The problem is that you are not storing your interval on component to remove it when component unmounts. Therefore, the interval will continue to be called even after the component is unmounted. You need to remove it with clearInterval():

export default class Feed extends Component {
  refresh() {
    this.myInterval = setInterval(() => this.setState({ reloading: false }), 4000)
  }

  componentWillUnmount() {
    clearInterval(this.myInterval);
  }
}


问:
What is the function of the & character in overloading std::cout?
I understand that the & character has various uses in c++, but I'm having trouble understanding what its function is in the code sample below (taken from here) (not its use in the left argument, but its use in std ostream&.

```<code>std::ostream& operator<< (std::ostream &out, const Point &point)
{
    // Since operator<< is a friend of the Point class, we can access Point's members directly.
    out << "Point(" << point.m_x << ", " << point.m_y << ", " << point.m_z << ")";

    return out;
}
</code>```

I think I understand the use of & when it represents a pass by reference inside a function parameter, but I can't see what it would do outside a function.

As far as I can see (which isn't very far at all), std::ostream is an class, which, when instantiated, can, via the operator <<, can be fed strings etc. to output to console. Then &out in the code above is a reference to an instance of std::ostream, (which will be std::cout?), which inside the function is fed point.m_x etc. and then returned so that multiple << operations can be performed.

I'm guessing the first instance of the & character is somehow communicating that the << operator defined in std::ostream is to be modified in some way, in order to allow it to function with members of the example Point class, but I want to have a better understanding than that.

答:
It means you are returning a reference to the object (in this case, it's the same object, out, that was passed in.

This is useful in chaining, it's what lets you do things like
a << b << c .... without having to create a copy of the object in question.

Body:
I understand that the & character has various uses in c++, but I'm having trouble understanding what its function is in the code sample below (taken from here) (not its use in the left argument, but its use in std ostream&.

std::ostream& operator<< (std::ostream &out, const Point &point)
{
    // Since operator<< is a friend of the Point class, we can access Point's members directly.
    out << "Point(" << point.m_x << ", " << point.m_y << ", " << point.m_z << ")";

    return out;
}

I think I understand the use of & when it represents a pass by reference inside a function parameter, but I can't see what it would do outside a function.

As far as I can see (which isn't very far at all), std::ostream is an class, which, when instantiated, can, via the operator <<, can be fed strings etc. to output to console. Then &out in the code above is a reference to an instance of std::ostream, (which will be std::cout?), which inside the function is fed point.m_x etc. and then returned so that multiple << operations can be performed.

I'm guessing the first instance of the & character is somehow communicating that the << operator defined in std::ostream is to be modified in some way, in order to allow it to function with members of the example Point class, but I want to have a better understanding than that.


问:
Error in the void print function
What I am trying to do is print out the elements that is dynamically allocated.

Here is my issue, I'm new in learning, and not understanding why this below cannot work? If you could please give a brief description why this is producing the error, I'm just trying to learn from my mistakes. I know I could just dynamically allocate the user input in the main function, but I wanted to see by trial and error if I could I just create an input function where I call it in my print function to produce the  user elements after it is dynamically allocated.

Any suggestion on what I could do to make this work would be awesome, thanks.

```<code>void print(int* input, int size)
{
    uinput(input,size);
    for(int i=0; i<size;i++)
    {
        std::cout << " " << input[i];// Error -> Thread 1:EXC_BAD_ACCESS (code=1,address=0x0)
    }
}
</code>```

The entire code without the print function above

```<code>#include <iostream>
void print(int*, int);
void uinput(int*, int);
int* copy(const int*, int);
int main()
{
    int size;
    int* input;
    std::cout << "Enter the size of the array";
    std::cin >> size;

    std::cout << "Original array:" << std::endl;

    print(input,size);
    int* expander = copy(input,size);

    std::cout << "New array:" << std::endl;

    print(expander,size);

    delete [] input;
    delete [] expander;
    input= nullptr;
    expander = nullptr;
    return 0;
}
void uinput(int* input, int size)
{
    int* uInput = new int[size];
    for(int k=0; k <size;k++)
    {
        std::cin >> uInput[k];
    }
}
int* copy(const int* input, int size)
{
    int* newArray = new int[size*2];
    int j =0;
    for(int i = 0; i <size*2;i++)
    {
        if(j >i)
        {
            newArray[j]=newArray[i];
            j++;
        }
        else
            newArray[j]=0;
    }

    return newArray;
}
</code>```

Update: I tried to modified where I just let it point to the size of uInput function, but that didn't work.

```<code>void uinput(int size)
{
    int* uInput = new int[size];
    for(int k=0; k <size;k++)
    {
        std::cin >> uInput[k];
    }
}
</code>```

答: Your uinput function allocates memory, but does not make use of the input parameter that you send it.  As a result, trying to iterate over items supposedly pointed to by that pointer, which has not been initialized to point at anything, is undefined behavior, causing your program to crash, in this case.

Title: Error in the void print function

Body:
What I am trying to do is print out the elements that is dynamically allocated.

Here is my issue, I'm new in learning, and not understanding why this below cannot work? If you could please give a brief description why this is producing the error, I'm just trying to learn from my mistakes. I know I could just dynamically allocate the user input in the main function, but I wanted to see by trial and error if I could I just create an input function where I call it in my print function to produce the  user elements after it is dynamically allocated.

Any suggestion on what I could do to make this work would be awesome, thanks.

void print(int* input, int size)
{
    uinput(input,size);
    for(int i=0; i<size;i++)
    {
        std::cout << " " << input[i];// Error -> Thread 1:EXC_BAD_ACCESS (code=1,address=0x0)
    }
}

The entire code without the print function above

#include <iostream>
void print(int*, int);
void uinput(int*, int);
int* copy(const int*, int);
int main()
{
    int size;
    int* input;
    std::cout << "Enter the size of the array";
    std::cin >> size;

    std::cout << "Original array:" << std::endl;

    print(input,size);
    int* expander = copy(input,size);

    std::cout << "New array:" << std::endl;

    print(expander,size);

    delete [] input;
    delete [] expander;
    input= nullptr;
    expander = nullptr;
    return 0;
}
void uinput(int* input, int size)
{
    int* uInput = new int[size];
    for(int k=0; k <size;k++)
    {
        std::cin >> uInput[k];
    }
}
int* copy(const int* input, int size)
{
    int* newArray = new int[size*2];
    int j =0;
    for(int i = 0; i <size*2;i++)
    {
        if(j >i)
        {
            newArray[j]=newArray[i];
            j++;
        }
        else
            newArray[j]=0;
    }

    return newArray;
}

Update: I tried to modified where I just let it point to the size of uInput function, but that didn't work.

void uinput(int size)
{
    int* uInput = new int[size];
    for(int k=0; k <size;k++)
    {
        std::cin >> uInput[k];
    }
}


问:
How to instruct gcc to warn me about invalid function pointer conversion just as g++ would do?
How can i instruct gcc to warn me about invalid function pointer conversions like g++ would do for the following piece of code?

And.. why doesn't gcc warn me about that? What could / will happen when passing a pointer to a to do_something()?

```<code>#include <stdio.h>

typedef void (*void_func_t) ();
typedef void (*void_int_func_t) (int, int, int);

void do_something(void_func_t f)
{
    void_int_func_t foo = f;
    foo(1,2,3);
}

void a()
{
    printf("a\n");
}

void b(int one, int two, int three)
{
    printf("%i, %i, %i\n", one, two, three);
}

int main()
{
    do_something(a);
    do_something(b);
    return 0;
}
</code>```

output:

```<code>➜  gcc -W -Wall -Werror func.c
➜  ./a.out
a
1, 2, 3
</code>```

c++, however would warn / give errors

```<code>g++ -W -Wall -Werror func.c
func.c: In function ‘void do_something(void_func_t)’:
func.c:8:27: error: invalid conversion from ‘void_func_t {aka void (*)()}’ to ‘void_int_func_t {aka void (*)(int, int, int)}’ [-fpermissive]
func.c: In function ‘int main()’:
func.c:25:19: error: invalid conversion from ‘void (*)(int, int, int)’ to ‘void_func_t {aka void (*)()}’ [-fpermissive]
func.c:6:6: error:   initializing argument 1 of ‘void do_something(void_func_t)’ [-fpermissive]
</code>```

答:
A function prototype with empty parenthesis is an obsolescent1 feature. Don't use it.

If you use the correct declaration, you will get warnings:

```<code>typedef void(*void_func_t)(void);
</code>```

Due to this old feature, the types void(*)() and void(*)(int, int, int) are compatible. The former type takes an unspecified number of arguments. This is doubly problematic, because there is no warning from the compiler, and if you call the function with incorrect number of arguments, the behavior is undefined.

Unlike in C, in C++ empty parenthesis mean that the function takes no arguments, thus void(*)() is equivalent to void(*)(void).

1 (Quoted from: ISO/IEC 9899:201x 6.11.6 Function declarators
1)

The use of function declarators with empty parentheses (not prototype-format parameter
type declarators) is an obsolescent feature.

Body:
How can i instruct gcc to warn me about invalid function pointer conversions like g++ would do for the following piece of code?

And.. why doesn't gcc warn me about that? What could / will happen when passing a pointer to a to do_something()?

#include <stdio.h>

typedef void (*void_func_t) ();
typedef void (*void_int_func_t) (int, int, int);

void do_something(void_func_t f)
{
    void_int_func_t foo = f;
    foo(1,2,3);
}

void a()
{
    printf("a\n");
}

void b(int one, int two, int three)
{
    printf("%i, %i, %i\n", one, two, three);
}

int main()
{
    do_something(a);
    do_something(b);
    return 0;
}

output:

➜  gcc -W -Wall -Werror func.c
➜  ./a.out
a
1, 2, 3

c++, however would warn / give errors

g++ -W -Wall -Werror func.c
func.c: In function ‘void do_something(void_func_t)’:
func.c:8:27: error: invalid conversion from ‘void_func_t {aka void (*)()}’ to ‘void_int_func_t {aka void (*)(int, int, int)}’ [-fpermissive]
func.c: In function ‘int main()’:
func.c:25:19: error: invalid conversion from ‘void (*)(int, int, int)’ to ‘void_func_t {aka void (*)()}’ [-fpermissive]
func.c:6:6: error:   initializing argument 1 of ‘void do_something(void_func_t)’ [-fpermissive]

Body:
A function prototype with empty parenthesis is an obsolescent1 feature. Don't use it.

If you use the correct declaration, you will get warnings:

typedef void(*void_func_t)(void);

Due to this old feature, the types void(*)() and void(*)(int, int, int) are compatible. The former type takes an unspecified number of arguments. This is doubly problematic, because there is no warning from the compiler, and if you call the function with incorrect number of arguments, the behavior is undefined.

Unlike in C, in C++ empty parenthesis mean that the function takes no arguments, thus void(*)() is equivalent to void(*)(void).

1 (Quoted from: ISO/IEC 9899:201x 6.11.6 Function declarators
1)

The use of function declarators with empty parentheses (not prototype-format parameter
type declarators) is an obsolescent feature.


问:
java interactive brokers api historical data and tick
brian was able to get a working example of this on 9.72 and with slight modification it can probably run in 9.73. The question was simple: look at current price and compare to previous day session high and low. If price is above it prints out buy, and if below low of historical previous session it would print out sell. At first I struggled due to my weak knowledge of Java, but brian displayed in his answer selected as best, how to use the current and historical prices for comparison. Very rudimentary, but important.

This is the current code that is supposed to take current price and compare it to prior session and if above high give a buy print out and if below low give a sell print out. In the 9.72 API this code did nothing because it did not properly connect data types.

```<code>    package apidemo;

    import java.io.IOException;
    import java.util.Set;
    import ib.client.TickType;
    import ib.client.CommissionReport;
    import ib.client.Contract;
    import ib.client.ContractDetails;
    import ib.client.DeltaNeutralContract;
    import ib.client.EClientSocket;
    import ib.client.EJavaSignal;
    import ib.client.EReader;
    import ib.client.EWrapper;
    import ib.client.Execution;
    import ib.client.Order;
    import ib.client.OrderState;
    import ib.client.SoftDollarTier;
    import ib.client.TagValue;
    import java.util.Vector;
    import com.ib.client.*;
    import com.ib.contracts.StkContract;
    import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    import java.util.Set;

  public class xxx implements EWrapper {
    EJavaSignal m_signal = new EJavaSignal();
    EClientSocket m_s = new EClientSocket(this, m_signal);
    // Keep track of the next ID
    private int nextOrderID = 0;
    // The IB API Client Socket object
    private EClientSocket client = null;
  private double high = Double.MAX_VALUE;
    private double low = -Double.MAX_VALUE;
    public static void main(String[] args) {
        new xxx().run();

    }

    private void run() {
        m_s.eConnect("localhost", 7497, 0);

        final EReader reader = new EReader(m_s, m_signal);

        reader.start();

        new Thread() {
            public void run() {
                while (m_s.isConnected()) {
                    m_signal.waitForSignal();
                    try {
                        javax.swing.SwingUtilities
                                .invokeAndWait(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            reader.processMsgs();
                                        } catch (IOException e) {
                                            error(e);
                                        }
                                    }
                                });
                    } catch (Exception e) {
                        error(e);
                    }
                }
            }
        }.start();
        Contract contract = new Contract ();
                 Order order = new Order();
                  m_s.reqMarketDataType(3);
                  //contract.m_localSymbol = "ESM7";

    }

    @Override public void nextValidId(int orderId) {
             System.out.println("id "+orderId);
        nextOrderID = orderId;
        Contract c = new Contract ();
          //contract.m_localSymbol = "ESM7";
        c.m_symbol = "EUR";
        c.m_exchange = "IDEALPRO";

        c.m_secType = "CASH";
        c.m_currency = "USD";
        m_s.reqHistoricalData(1, c,
                LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)+ " 16:00:00",
                "2 D", "1 day", "MIDPOINT", 1, 1, null);
        m_s.reqMktData(1, c, "", false, null);

    }
   public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {
      System.out.println("date xxx"+date);
        this.high = high;
        this.low = low;
        System.out.println(high);
         System.out.println(low);
          System.out.println("xxx");
        }
 public void tickPrice(int orderId, int field, double price,
            int canAutoExecute)
    {
        System.out.println(high);
         System.out.println(low);
         System.out.println("idx: "+orderId + " " + TickType.getField(field) + " pricex: "+price);
       if (field == TickType.LAST.index()){
            if (price > high) {
                System.out.println("buy");
            }
            if (price < low){
                System.out.println("sell");
            }
        }
    }
        @Override public void connectionClosed() {
        }

    }
</code>```

This code currently has out put like the following:

```<code>id 1836254
date xxx20170328
1.08727
1.079905
xxx
date xxx20170329
1.08267
1.073995
xxx
date xxxfinished-20170327  16:00:00-20170329  16:00:00
-1.0
-1.0
xxx
-1.0
-1.0
idx: 1 bidPrice pricex: 1.07658
-1.0
-1.0
idx: 1 askPrice pricex: 1.07659
-1.0
-1.0
</code>```

Notice the high and low daily are showed for two sessions, that is truly amazing. But when trying to use those high and lows in tickprice it is not being remembered and returns -1.

答:
I removed a bunch of stuff from your code and added the parts needed.  After connecting wait for nextValidId to start requesting stuff.  Get the history and set highs and lows.  Get mktData and check the last price, buy/sell as needed.

```<code>import com.ib.client.*;
import com.ib.contracts.StkContract;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Set;

public class Test implements EWrapper {
    EJavaSignal m_signal = new EJavaSignal();
    EClientSocket m_client = new EClientSocket(this, m_signal);

    private int nextOrderID = 0;
    private double high = Double.MAX_VALUE;
    private double low = -Double.MAX_VALUE;

    public static void main(String[] args) {
        new Test.run();
    }

    private void run() {
        m_client.eConnect("localhost", 7497, 123);
        final EReader reader = new EReader(m_client, m_signal);
        reader.start();
        new Thread() {
            @Override
            public void run() {
                while (m_client.isConnected()) {
                    m_signal.waitForSignal();
                    try {
                        reader.processMsgs();
                    } catch (Exception e) {
                        System.out.println("Exception: " + e.getMessage());
                    }
                }
            }
        }.start();
    }

    @Override
    public void nextValidId(int orderId) {
        System.out.println("id "+orderId);
        nextOrderID = orderId;
        Contract c = new StkContract("IBKR");
        m_client.reqHistoricalData(1, c,
                LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)+ " 16:00:00",
                "2 D", "1 day", "TRADES", 1, 1, null);
        m_client.reqMktData(1, c, "", false, null);
    }

    @Override
    public void error(int id, int errorCode, String errorMsg) {
        System.out.println(id + " " + errorCode + " " + errorMsg);
    }

    @Override
    public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {
        //if being run on the next calendar day, this works
        if (LocalDate.now().minusDays(1).format(DateTimeFormatter.BASIC_ISO_DATE).equals(date)){
            this.high = high;
            this.low = low;
            System.out.println(date + " h: " + high + " l: " +low);
        }
    }

    @Override
        public void tickPrice(int tickerId, int field, double price, int canAutoExecute) {

        System.out.println("id: "+tickerId + " " + TickType.getField(field) + " price: "+price);
        if (field == TickType.LAST.index()){
            if (price > high) {
                System.out.println("buy");
            }
            if (price < low){
                System.out.println("sell");
            }
        }

    }
 //impl rest of EWrapper
}
</code>```

output

```<code>id 130002
-1 2104 Market data farm connection is OK:usfuture
-1 2104 Market data farm connection is OK:cashfarm
-1 2104 Market data farm connection is OK:cafarm
-1 2104 Market data farm connection is OK:usfarm
-1 2106 HMDS data farm connection is OK:ushmds
date 20170328
date 20170329
date finished-20170327  16:00:00-20170329  16:00:00
id: 1 bidPrice price: 34.74
id: 1 askPrice price: 34.82
id: 1 lastPrice price: 34.73
buy
id: 1 high price: 34.87
id: 1 low price: 34.56
</code>```

Body:
brian was able to get a working example of this on 9.72 and with slight modification it can probably run in 9.73. The question was simple: look at current price and compare to previous day session high and low. If price is above it prints out buy, and if below low of historical previous session it would print out sell. At first I struggled due to my weak knowledge of Java, but brian displayed in his answer selected as best, how to use the current and historical prices for comparison. Very rudimentary, but important.

This is the current code that is supposed to take current price and compare it to prior session and if above high give a buy print out and if below low give a sell print out. In the 9.72 API this code did nothing because it did not properly connect data types.

    package apidemo;

    import java.io.IOException;
    import java.util.Set;
    import ib.client.TickType;
    import ib.client.CommissionReport;
    import ib.client.Contract;
    import ib.client.ContractDetails;
    import ib.client.DeltaNeutralContract;
    import ib.client.EClientSocket;
    import ib.client.EJavaSignal;
    import ib.client.EReader;
    import ib.client.EWrapper;
    import ib.client.Execution;
    import ib.client.Order;
    import ib.client.OrderState;
    import ib.client.SoftDollarTier;
    import ib.client.TagValue;
    import java.util.Vector;
    import com.ib.client.*;
    import com.ib.contracts.StkContract;
    import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    import java.util.Set;

  public class xxx implements EWrapper {
    EJavaSignal m_signal = new EJavaSignal();
    EClientSocket m_s = new EClientSocket(this, m_signal);
    // Keep track of the next ID
    private int nextOrderID = 0;
    // The IB API Client Socket object
    private EClientSocket client = null;
  private double high = Double.MAX_VALUE;
    private double low = -Double.MAX_VALUE;
    public static void main(String[] args) {
        new xxx().run();

    }

    private void run() {
        m_s.eConnect("localhost", 7497, 0);

        final EReader reader = new EReader(m_s, m_signal);

        reader.start();

        new Thread() {
            public void run() {
                while (m_s.isConnected()) {
                    m_signal.waitForSignal();
                    try {
                        javax.swing.SwingUtilities
                                .invokeAndWait(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            reader.processMsgs();
                                        } catch (IOException e) {
                                            error(e);
                                        }
                                    }
                                });
                    } catch (Exception e) {
                        error(e);
                    }
                }
            }
        }.start();
        Contract contract = new Contract ();
                 Order order = new Order();
                  m_s.reqMarketDataType(3);
                  //contract.m_localSymbol = "ESM7";

    }

    @Override public void nextValidId(int orderId) {
             System.out.println("id "+orderId);
        nextOrderID = orderId;
        Contract c = new Contract ();
          //contract.m_localSymbol = "ESM7";
        c.m_symbol = "EUR";
        c.m_exchange = "IDEALPRO";

        c.m_secType = "CASH";
        c.m_currency = "USD";
        m_s.reqHistoricalData(1, c,
                LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)+ " 16:00:00",
                "2 D", "1 day", "MIDPOINT", 1, 1, null);
        m_s.reqMktData(1, c, "", false, null);

    }
   public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {
      System.out.println("date xxx"+date);
        this.high = high;
        this.low = low;
        System.out.println(high);
         System.out.println(low);
          System.out.println("xxx");
        }
 public void tickPrice(int orderId, int field, double price,
            int canAutoExecute)
    {
        System.out.println(high);
         System.out.println(low);
         System.out.println("idx: "+orderId + " " + TickType.getField(field) + " pricex: "+price);
       if (field == TickType.LAST.index()){
            if (price > high) {
                System.out.println("buy");
            }
            if (price < low){
                System.out.println("sell");
            }
        }
    }
        @Override public void connectionClosed() {
        }

    }

This code currently has out put like the following:

id 1836254
date xxx20170328
1.08727
1.079905
xxx
date xxx20170329
1.08267
1.073995
xxx
date xxxfinished-20170327  16:00:00-20170329  16:00:00
-1.0
-1.0
xxx
-1.0
-1.0
idx: 1 bidPrice pricex: 1.07658
-1.0
-1.0
idx: 1 askPrice pricex: 1.07659
-1.0
-1.0

Notice the high and low daily are showed for two sessions, that is truly amazing. But when trying to use those high and lows in tickprice it is not being remembered and returns -1.

Body:
I removed a bunch of stuff from your code and added the parts needed.  After connecting wait for nextValidId to start requesting stuff.  Get the history and set highs and lows.  Get mktData and check the last price, buy/sell as needed.

import com.ib.client.*;
import com.ib.contracts.StkContract;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Set;

public class Test implements EWrapper {
    EJavaSignal m_signal = new EJavaSignal();
    EClientSocket m_client = new EClientSocket(this, m_signal);

    private int nextOrderID = 0;
    private double high = Double.MAX_VALUE;
    private double low = -Double.MAX_VALUE;

    public static void main(String[] args) {
        new Test.run();
    }

    private void run() {
        m_client.eConnect("localhost", 7497, 123);
        final EReader reader = new EReader(m_client, m_signal);
        reader.start();
        new Thread() {
            @Override
            public void run() {
                while (m_client.isConnected()) {
                    m_signal.waitForSignal();
                    try {
                        reader.processMsgs();
                    } catch (Exception e) {
                        System.out.println("Exception: " + e.getMessage());
                    }
                }
            }
        }.start();
    }

    @Override
    public void nextValidId(int orderId) {
        System.out.println("id "+orderId);
        nextOrderID = orderId;
        Contract c = new StkContract("IBKR");
        m_client.reqHistoricalData(1, c,
                LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)+ " 16:00:00",
                "2 D", "1 day", "TRADES", 1, 1, null);
        m_client.reqMktData(1, c, "", false, null);
    }

    @Override
    public void error(int id, int errorCode, String errorMsg) {
        System.out.println(id + " " + errorCode + " " + errorMsg);
    }

    @Override
    public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {
        //if being run on the next calendar day, this works
        if (LocalDate.now().minusDays(1).format(DateTimeFormatter.BASIC_ISO_DATE).equals(date)){
            this.high = high;
            this.low = low;
            System.out.println(date + " h: " + high + " l: " +low);
        }
    }

    @Override
        public void tickPrice(int tickerId, int field, double price, int canAutoExecute) {

        System.out.println("id: "+tickerId + " " + TickType.getField(field) + " price: "+price);
        if (field == TickType.LAST.index()){
            if (price > high) {
                System.out.println("buy");
            }
            if (price < low){
                System.out.println("sell");
            }
        }

    }
 //impl rest of EWrapper
}

output

id 130002
-1 2104 Market data farm connection is OK:usfuture
-1 2104 Market data farm connection is OK:cashfarm
-1 2104 Market data farm connection is OK:cafarm
-1 2104 Market data farm connection is OK:usfarm
-1 2106 HMDS data farm connection is OK:ushmds
date 20170328
date 20170329
date finished-20170327  16:00:00-20170329  16:00:00
id: 1 bidPrice price: 34.74
id: 1 askPrice price: 34.82
id: 1 lastPrice price: 34.73
buy
id: 1 high price: 34.87
id: 1 low price: 34.56


问:
Ionic + AngularJS: ng-repeat filter not working on grid layout but works in list
I am currently learning building apps with ionic v1 and angular.

Here's the scenario, I'm trying to make a grid of cards and was able to do it by following the tutorial on this link.

I was able to populate the grid with cards using json data. However, I also need to add a search box in order to filter the results. I used angularJS ng-repeat filter on the view but it is not filtering it correctly.

here's my code:

```<code> angular.module('starter')

.factory('Disasters', function() {
   var disasters= [{
       id: 0,
       name: 'Earthquake',
       face: 'img/earthquake/thumbs.PNG',
   }, {
      id: 1,
      name: 'Flash Floods',
      face: 'img/flood/thumbs.png',
   }, {
      id: 2,
      name: 'Typhoon',
      face: 'img/typhoon/thumbs.png',
   }, {
      id: 3,
      name: 'Avalanche',
      face: 'img/avalanche/thumbs.png',
   }];

   return {
     all: function() {
         return disasters;
     },
     remove: function(disaster) {
         disasters.splice(disasters.indexOf(disaster), 1);
     },
     get: function(disasterID) {
        for (var i = 0; i < disasters.length; i++) {
           if (disasters[i].id === parseInt(disasterID)) {
        return disasters[i];
     }
   }
   return null;
  }
 };
})

.controller('DisasterCtrl', function($scope,$state,$ionicSideMenuDelegate,Chats,Facts){

  $scope.disasters = Disasters.all();
})
</code>```

and here's the code for my view

```<code><ion-content>
  <input type="text" ng-model="search">
  <div ng-repeat="disaster in disasters | filter: search" ng-if="$index % 2 === 0">
    <div class="row">
      <div class="col col-50 no-padding" ng-if="$index < disasters.length">
      <div class="list card card-cell">
        <div class="item item-image background-image" back-img="{{disasters[$index].slider[0].image}}">
          </div>
        <div class="item item-avatar" ng-click="href({{disasters[$index].id}})">
          <p class="bold uppercase font12">{{disasters[$index].name}}</p>
        </div>
      </div>
    </div>

    <div class="col col-50 no-padding" ng-if="$index < disasters.length">
      <div class="list card card-cell">
        <div class="item item-image background-image" back-img="{{disasters[$index + 1].slider[0].image}}">
          </div>
        <div class="item item-avatar" ng-click="href({{disasters[$index + 1].id}})">
          <p class="bold uppercase font12">{{disasters[$index + 1].name}}</p>
        </div>
      </div>
    </div>
    </div>

  </div>
</ion-content>
</code>```

when I type something on the search text box it always shows the first two object in the JSON data.

If I change the view into a list the filter works, however it is required to apply the grid styling on the view.

Thanks!

Pluker link of the code : plnk code link

答:
The problem with your grid layouting is that you are using the ng-repeat in a row instead of the columns so when the search item is among a particular it returns the full row because thats where your item is located. so i created a code to help you sort it in plnk where i used the ng-repeat in a column instead of the row and added a style to the row to make it break which is this

class="row" style="flex-wrap: wrap;"

```<code>    Input: <input type="text" ng-model="search.name" style="border:1px solid #ccc">

<br>
<div class="row" style="flex-wrap: wrap;" >
  <div class="col col-50 no-padding" ng-repeat="disaster in disasters | filter: search" >
      {{$index}}
      <div class="list card card-cell">
        <div class="item item-image background-image" back-img="{{disaster.slider[0].image}}">
          </div>
        <div class="item item-avatar" ng-click="href({{disaster.id}})">
          <p class="bold uppercase font12">{{disaster.name}}</p>
        </div>
      </div>

    </div>
</div>
</code>```

That should work for you as needed. here is the demo running demo
reference from this answer

Body:
I am currently learning building apps with ionic v1 and angular.

Here's the scenario, I'm trying to make a grid of cards and was able to do it by following the tutorial on this link.

I was able to populate the grid with cards using json data. However, I also need to add a search box in order to filter the results. I used angularJS ng-repeat filter on the view but it is not filtering it correctly.

here's my code:

 angular.module('starter')

.factory('Disasters', function() {
   var disasters= [{
       id: 0,
       name: 'Earthquake',
       face: 'img/earthquake/thumbs.PNG',
   }, {
      id: 1,
      name: 'Flash Floods',
      face: 'img/flood/thumbs.png',
   }, {
      id: 2,
      name: 'Typhoon',
      face: 'img/typhoon/thumbs.png',
   }, {
      id: 3,
      name: 'Avalanche',
      face: 'img/avalanche/thumbs.png',
   }];

   return {
     all: function() {
         return disasters;
     },
     remove: function(disaster) {
         disasters.splice(disasters.indexOf(disaster), 1);
     },
     get: function(disasterID) {
        for (var i = 0; i < disasters.length; i++) {
           if (disasters[i].id === parseInt(disasterID)) {
        return disasters[i];
     }
   }
   return null;
  }
 };
})

.controller('DisasterCtrl', function($scope,$state,$ionicSideMenuDelegate,Chats,Facts){

  $scope.disasters = Disasters.all();
})

and here's the code for my view

<ion-content>
  <input type="text" ng-model="search">

      <div class="col col-50 no-padding" ng-if="$index < disasters.length">

{{disasters[$index].name}}

    <div class="col col-50 no-padding" ng-if="$index < disasters.length">

{{disasters[$index + 1].name}}

</ion-content>

when I type something on the search text box it always shows the first two object in the JSON data.

If I change the view into a list the filter works, however it is required to apply the grid styling on the view.

Thanks!

Pluker link of the code : plnk code link

Body:
The problem with your grid layouting is that you are using the ng-repeat in a row instead of the columns so when the search item is among a particular it returns the full row because thats where your item is located. so i created a code to help you sort it in plnk where i used the ng-repeat in a column instead of the row and added a style to the row to make it break which is this

class="row" style="flex-wrap: wrap;"

    Input: <input type="text" ng-model="search.name" style="border:1px solid #ccc">

<br>
<div class="row" style="flex-wrap: wrap;" >
  <div class="col col-50 no-padding" ng-repeat="disaster in disasters | filter: search" >
      {{$index}}
      <div class="list card card-cell">
        <div class="item item-image background-image" back-img="{{disaster.slider[0].image}}">
          </div>
        <div class="item item-avatar" ng-click="href({{disaster.id}})">
          <p class="bold uppercase font12">{{disaster.name}}</p>
        </div>
      </div>

    </div>
</div>

That should work for you as needed. here is the demo running demo
reference from this answer


问:
phpmail always go to spam
how to optimize php_mail() w/o sending the email to a spam?
everything that my webpage is doing sends the email into spam?how to make it not go to spam??</p>

答:
Either you are using a black listed ISP -- check if SPAMHUAS has put them on thier blacklist.

Or your emails look like SPAM to most common spam filters. Either because of the content, (does it look like you are selling Kalashnikovs or drugs that give you a boner) , or, because you have sent thousnads of identical e-mails to the same SMTP server.

Or your e-mail content could be so annoying that many users have hit the "report spam" button.

Incidently even if you are not intending to send lots of e-mails its worth checking out of an ISP is blacklisted before you sign up. That they allow spammers to use there IP is a good indication of thier attitude to thier customers and the public in general.

ContentLicense: CC BY-SA 2.5

Title: phpmail always go to spam


问:
Merging columns and removing duplicates with Pandas
I need to merge similar columns and remove duplicates (entries with the same date). The data frame:

```<code>     Albumin  C-reactive protein    CRP  Ferritin  Haemoglobin     Hb  Iron  Nancy Index  Plasma  Platelets  Transferrin saturation %  Transferrin saturations  UCEIS (0 to 8)    WCC  White Cell Count           test_date
0        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN             12.35 2016-04-17 23:00:00
1        NaN                 NaN    NaN       NaN        133.0    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
2        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN      406.0                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
3        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN      406.0                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
4        NaN                32.2    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
5       36.0                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
6        NaN                 NaN    NaN      99.7          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
7        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                      25.0                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
12      36.0                 NaN   32.2      99.7          NaN  133.0   NaN          NaN     NaN      406.0                       NaN                     25.0             NaN  12.35               NaN 2016-04-17 23:00:00
14       NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             7.0    NaN               NaN 2016-04-25 23:00:00
79      34.0                 NaN    5.4      55.9          NaN  133.0   NaN          NaN     NaN      372.0                       NaN                     28.0             NaN   7.99               NaN 2016-06-12 23:00:00
</code>```

I need to get:

```<code>     Albumin    CRP  Ferritin     Hb  Nancy Index  Plasma  Platelets  Transferrin saturations  UCEIS (0 to 8)    WCC           test_date
12      36.0   32.2      99.7  133.0          NaN     NaN      406.0                     25.0             NaN  12.35 2016-04-17 23:00:00
14       NaN    NaN       NaN    NaN          NaN     NaN        NaN                      NaN             7.0    NaN 2016-04-25 23:00:00
79      34.0    5.4      55.9  133.0          NaN     NaN      372.0                     28.0             NaN   7.99 2016-06-12 23:00:00
</code>```

So, columns 'C-reactive protein' should be merged with 'CRP', 'Hemoglobin' with 'Hb', 'Transferrin saturation %' with 'Transferrin saturation'.

I can easily remove duplicates with .drop_duplicates(), but the trick is remove not only row with the same date, but also to make sure, that the values in the same column are duplicated. For example, 'C-reactive protein' at row '4' has the same values as 'CRP' in row '12', in addition, they both have the same entry date. Given all that, I need to have only 'CRP' column with values 32.2 and the date '2016-04-17' (plus other unique columns).

EDIT

Some entries are really duplicates (absolutely identical, due to system glitches), for example (last three rows, on 2016-06-20, indices '803' and '122'). Is the solution below capable of removing such identical rows?

P.S. Thanks for the amazing and general solution for duplicate, but not identical entries.

```<code>     Albumin  C-reactive protein  CRP  Ferritin  Haemoglobin     Hb  Iron  Nancy Index  Plasma  Platelets  Transferrin saturation %  Transferrin saturations  UCEIS (0 to 8)   WCC  White Cell Count          setName           test_date
735     39.0                 NaN  0.4      52.0          NaN  144.0   NaN          NaN     NaN      197.0                       NaN                     25.0             NaN  4.88               NaN           Bloods 2016-05-31 23:00:00
803     40.0                 NaN  0.2      81.0          NaN  147.0   NaN          NaN     NaN      234.0                       NaN                     35.0             NaN  8.47               NaN           Bloods 2016-06-20 23:00:00
347      NaN                 NaN  NaN       NaN          NaN    NaN   NaN          NaN     1.0        NaN                       NaN                      NaN             NaN   NaN               NaN  Research Bloods 2016-06-20 23:00:00
122     40.0                 NaN  0.2      81.9          NaN  147.0   NaN          NaN     NaN      234.0                       NaN                     35.0             NaN  8.47               NaN           Bloods 2016-06-20 23:00:00
</code>```

答:
What @jezrael was saying is that if you had a situation where:

```<code>     Albumin  C-reactive protein    CRP  test_date
0        NaN                 NaN    32       2016-04-17 23:00:00
1        NaN                 8.0    NaN      2016-04-17 23:00:00
</code>```

then his method would erase the 8.0 reading and keep only the 32 (this is because he does it in two steps (or 3?), in this line: df = df.groupby('test_date').max().rename(columns=d).groupby(axis=1, level=0).max()

```<code>df = df.groupby('test_date').max() # selects max of each column
                                   # while collapsing 'test_date'
</code>```

which for my truncated example would give:

```<code>         Albumin  C-reactive protein    CRP  test_date
0        NaN                 8.0    32       2016-04-17 23:00:00
</code>```

then rename .rename(columns=d) giving:

```<code>         Albumin  CRP    CRP  test_date
0        NaN      8.0    32   2016-04-17 23:00:00
</code>```

then .groupby(axis=1, level=0).max() to group along rows (instead of down columns) which gives:

```<code>         Albumin  CRP  test_date
0        NaN      32   2016-04-17 23:00:00
</code>```

which is where you run the highest risk of losing data.

Alternative

I would split the original data into two frames first

```<code>df1 = df[["C-reactive protein","Haemoglobin", ...]]
df2 = df[["CRP", "Hb"]]

# then rename

df2 = df2.rename(columns={"CRP":"C-reactive protein", "Hb":"Haemoglobin", ...})

# use concat to stack them on one another

df3 = pd.concat([df1, df2]) # i've run out of names

df3 = df3.drop_duplicates() # perhaps also drop NAs?
</code>```

but this is only necessary if you have multiple non-duplicate entries for the same test on the same day.

Body:
I need to merge similar columns and remove duplicates (entries with the same date). The data frame:

     Albumin  C-reactive protein    CRP  Ferritin  Haemoglobin     Hb  Iron  Nancy Index  Plasma  Platelets  Transferrin saturation %  Transferrin saturations  UCEIS (0 to 8)    WCC  White Cell Count           test_date
0        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN             12.35 2016-04-17 23:00:00
1        NaN                 NaN    NaN       NaN        133.0    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
2        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN      406.0                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
3        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN      406.0                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
4        NaN                32.2    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
5       36.0                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
6        NaN                 NaN    NaN      99.7          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
7        NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                      25.0                      NaN             NaN    NaN               NaN 2016-04-17 23:00:00
12      36.0                 NaN   32.2      99.7          NaN  133.0   NaN          NaN     NaN      406.0                       NaN                     25.0             NaN  12.35               NaN 2016-04-17 23:00:00
14       NaN                 NaN    NaN       NaN          NaN    NaN   NaN          NaN     NaN        NaN                       NaN                      NaN             7.0    NaN               NaN 2016-04-25 23:00:00
79      34.0                 NaN    5.4      55.9          NaN  133.0   NaN          NaN     NaN      372.0                       NaN                     28.0             NaN   7.99               NaN 2016-06-12 23:00:00

I need to get:

     Albumin    CRP  Ferritin     Hb  Nancy Index  Plasma  Platelets  Transferrin saturations  UCEIS (0 to 8)    WCC           test_date
12      36.0   32.2      99.7  133.0          NaN     NaN      406.0                     25.0             NaN  12.35 2016-04-17 23:00:00
14       NaN    NaN       NaN    NaN          NaN     NaN        NaN                      NaN             7.0    NaN 2016-04-25 23:00:00
79      34.0    5.4      55.9  133.0          NaN     NaN      372.0                     28.0             NaN   7.99 2016-06-12 23:00:00

So, columns 'C-reactive protein' should be merged with 'CRP', 'Hemoglobin' with 'Hb', 'Transferrin saturation %' with 'Transferrin saturation'.

I can easily remove duplicates with .drop_duplicates(), but the trick is remove not only row with the same date, but also to make sure, that the values in the same column are duplicated. For example, 'C-reactive protein' at row '4' has the same values as 'CRP' in row '12', in addition, they both have the same entry date. Given all that, I need to have only 'CRP' column with values 32.2 and the date '2016-04-17' (plus other unique columns).

EDIT

Some entries are really duplicates (absolutely identical, due to system glitches), for example (last three rows, on 2016-06-20, indices '803' and '122'). Is the solution below capable of removing such identical rows?

P.S. Thanks for the amazing and general solution for duplicate, but not identical entries.

     Albumin  C-reactive protein  CRP  Ferritin  Haemoglobin     Hb  Iron  Nancy Index  Plasma  Platelets  Transferrin saturation %  Transferrin saturations  UCEIS (0 to 8)   WCC  White Cell Count          setName           test_date
735     39.0                 NaN  0.4      52.0          NaN  144.0   NaN          NaN     NaN      197.0                       NaN                     25.0             NaN  4.88               NaN           Bloods 2016-05-31 23:00:00
803     40.0                 NaN  0.2      81.0          NaN  147.0   NaN          NaN     NaN      234.0                       NaN                     35.0             NaN  8.47               NaN           Bloods 2016-06-20 23:00:00
347      NaN                 NaN  NaN       NaN          NaN    NaN   NaN          NaN     1.0        NaN                       NaN                      NaN             NaN   NaN               NaN  Research Bloods 2016-06-20 23:00:00
122     40.0                 NaN  0.2      81.9          NaN  147.0   NaN          NaN     NaN      234.0                       NaN                     35.0             NaN  8.47               NaN           Bloods 2016-06-20 23:00:00

Body:
What @jezrael was saying is that if you had a situation where:

     Albumin  C-reactive protein    CRP  test_date
0        NaN                 NaN    32       2016-04-17 23:00:00
1        NaN                 8.0    NaN      2016-04-17 23:00:00

then his method would erase the 8.0 reading and keep only the 32 (this is because he does it in two steps (or 3?), in this line: df = df.groupby('test_date').max().rename(columns=d).groupby(axis=1, level=0).max()

df = df.groupby('test_date').max() # selects max of each column
                                   # while collapsing 'test_date'

which for my truncated example would give:

         Albumin  C-reactive protein    CRP  test_date
0        NaN                 8.0    32       2016-04-17 23:00:00

then rename .rename(columns=d) giving:

         Albumin  CRP    CRP  test_date
0        NaN      8.0    32   2016-04-17 23:00:00

then .groupby(axis=1, level=0).max() to group along rows (instead of down columns) which gives:

         Albumin  CRP  test_date
0        NaN      32   2016-04-17 23:00:00

which is where you run the highest risk of losing data.

Alternative

I would split the original data into two frames first

df1 = df[["C-reactive protein","Haemoglobin", ...]]
df2 = df[["CRP", "Hb"]]

# then rename

df2 = df2.rename(columns={"CRP":"C-reactive protein", "Hb":"Haemoglobin", ...})

# use concat to stack them on one another

df3 = pd.concat([df1, df2]) # i've run out of names

df3 = df3.drop_duplicates() # perhaps also drop NAs?

but this is only necessary if you have multiple non-duplicate entries for the same test on the same day.


问:
How to feed intermediate result in the tensorflow graph into tf.py_func as [inp]?
I have implemented a custom pooling layer using numpy like this:

```<code>def pooling_np(input):
#input:[batch,h,v,channel]
#output:[batch,h/2,v/2,channel]
pooling = np.empty([input.shape[0], input.shape[1]/2, input.shape[2]/2, input.shape[3]])
for i_batch in range(input.shape[0]):
    for j_channel in range(input.shape[-1]):
        max_id = np.argmax(input[i_batch,:,:,j_channel])
        #[i_batch,max_h,max_v,j_channel]
        max_h = max_id / input.shape[1]
        max_v = max_id % input.shape[1]
        #begin point:(left,up)
        left = max(min(max_h - input.shape[1]/4, input.shape[1]/2), 0)
        up = max(min(max_v - input.shape[2]/4, input.shape[2]/2), 0)
        pooling[i_batch,:,:,j_channel] = input[i_batch,left:left+input.shape[1]/2,up:up+input.shape[2]/2,j_channel]
return pooling
</code>```

Then I want to incorporate this new pooling layer in a tensorflow alexnet graph using tf.py_func like this:

```<code>with graph.as_default():
...
#conv5
#conv(3, 3, 256, 1, 1, group=2, name='conv5')
k_h = 3; k_w = 3; c_o = 256; s_h = 1; s_w = 1; group = 2
conv5W = tf.Variable(net_data["conv5"][0])
conv5b = tf.Variable(net_data["conv5"][1])
conv5_in = conv(conv4, conv5W, conv5b, k_h, k_w, c_o, s_h, s_w, padding="SAME", group=group)
conv5 = tf.nn.relu(conv5_in)

#newpool5:custom a new pooling layer
newpool5 = tf.py_func(adaptive_pooling_np, [conv5], tf.float32)
adaptivepool5.set_shape([conv5.get_shape()[0],conv5.get_shape()[1]/2,conv5.get_shape()[2]/2,conv5.get_shape()[-1]])
adaptivepool5 = tf.cast(adaptivepool5, tf.float32)

#fc6
#fc(4096, name='fc6')
fc6W = tf.Variable(net_data["fc6"][0])
fc6b = tf.Variable(net_data["fc6"][1])
fc6 = tf.nn.relu_layer(tf.reshape(newpool5, [-1, int(prod(newpool5.get_shape()[1:]))]), fc6W, fc6b)
...
with tf.Session(graph=graph, config = config) as session:
tf.global_variables_initializer().run()
print('Initialized')
t = time.time()
feed_dict = {x:testset}
output = session.run(prob, feed_dict = feed_dict)
</code>```

I want to use conv5 as [inp] of tf.py_func because I cannot create a tf.placeholder and feed the intermediate value of the graph(here:conv5) in the beginning of the tf session.

However, there is an error like this:

```<code>    Initialized
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-19-2b38ea266e1a> in <module>()
      6     t = time.time()
      7     feed_dict = {x:testset}
----> 8     output = session.run(prob, feed_dict = feed_dict)
      9     #adaptivepooling5 = session.run(adappool5, feed_dict = feed_dict)
     10     print(conv5.shape)

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    765     try:
    766       result = self._run(None, fetches, feed_dict, options_ptr,
--> 767                          run_metadata_ptr)
    768       if run_metadata:
    769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
    963     if final_fetches or final_targets:
    964       results = self._do_run(handle, final_targets, final_fetches,
--> 965                              feed_dict_string, options, run_metadata)
    966     else:
    967       results = []

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1013     if handle is None:
   1014       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1015                            target_list, options, run_metadata)
   1016     else:
   1017       return self._do_call(_prun_fn, self._session, handle, feed_dict,

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)
   1033         except KeyError:
   1034           pass
-> 1035       raise type(e)(node_def, op, message)
   1036
   1037   def _extend_graph(self):

InvalidArgumentError: 0-th value returned by pyfunc_8 is double, but expects float
     [[Node: PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_8", _device="/job:localhost/replica:0/task:0/cpu:0"](Relu_4/_3)]]
     [[Node: PyFunc/_5 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_86_PyFunc", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

Caused by op u'PyFunc', defined at:
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelapp.py", line 474, in start
    ioloop.IOLoop.instance().start()
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 887, in start
    handler_func(fd_obj, events)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 276, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 390, in execute_request
    user_expressions, allow_stdin)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/zmqshell.py", line 501, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2717, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2821, in run_ast_nodes
    if self.run_code(code, result):
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-17-90b8573e003c>", line 91, in <module>
    adaptivepool5 = tf.py_func(adaptive_pooling_np, [conv5], tf.float32)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/script_ops.py", line 189, in py_func
    input=inp, token=token, Tout=Tout, name=name)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_script_ops.py", line 40, in _py_func
    name=name)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2327, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1226, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): 0-th value returned by pyfunc_8 is double, but expects float
     [[Node: PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_8", _device="/job:localhost/replica:0/task:0/cpu:0"](Relu_4/_3)]]
     [[Node: PyFunc/_5 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_86_PyFunc", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
</code>```

How can I use this numpy function in tensorflow?

答:
Your py_func is returning a tf.float64 instead of a tf.float32, which is the declared type.

Change the line to say

```<code>newpool5 = tf.py_func(adaptive_pooling_np, [conv5], tf.float64)
</code>```

and things will be fine.

Body:
I have implemented a custom pooling layer using numpy like this:

def pooling_np(input):
#input:[batch,h,v,channel]
#output:[batch,h/2,v/2,channel]
pooling = np.empty([input.shape[0], input.shape[1]/2, input.shape[2]/2, input.shape[3]])
for i_batch in range(input.shape[0]):
    for j_channel in range(input.shape[-1]):
        max_id = np.argmax(input[i_batch,:,:,j_channel])
        #[i_batch,max_h,max_v,j_channel]
        max_h = max_id / input.shape[1]
        max_v = max_id % input.shape[1]
        #begin point:(left,up)
        left = max(min(max_h - input.shape[1]/4, input.shape[1]/2), 0)
        up = max(min(max_v - input.shape[2]/4, input.shape[2]/2), 0)
        pooling[i_batch,:,:,j_channel] = input[i_batch,left:left+input.shape[1]/2,up:up+input.shape[2]/2,j_channel]
return pooling

Then I want to incorporate this new pooling layer in a tensorflow alexnet graph using tf.py_func like this:

with graph.as_default():
...
#conv5
#conv(3, 3, 256, 1, 1, group=2, name='conv5')
k_h = 3; k_w = 3; c_o = 256; s_h = 1; s_w = 1; group = 2
conv5W = tf.Variable(net_data["conv5"][0])
conv5b = tf.Variable(net_data["conv5"][1])
conv5_in = conv(conv4, conv5W, conv5b, k_h, k_w, c_o, s_h, s_w, padding="SAME", group=group)
conv5 = tf.nn.relu(conv5_in)

#newpool5:custom a new pooling layer
newpool5 = tf.py_func(adaptive_pooling_np, [conv5], tf.float32)
adaptivepool5.set_shape([conv5.get_shape()[0],conv5.get_shape()[1]/2,conv5.get_shape()[2]/2,conv5.get_shape()[-1]])
adaptivepool5 = tf.cast(adaptivepool5, tf.float32)

#fc6
#fc(4096, name='fc6')
fc6W = tf.Variable(net_data["fc6"][0])
fc6b = tf.Variable(net_data["fc6"][1])
fc6 = tf.nn.relu_layer(tf.reshape(newpool5, [-1, int(prod(newpool5.get_shape()[1:]))]), fc6W, fc6b)
...
with tf.Session(graph=graph, config = config) as session:
tf.global_variables_initializer().run()
print('Initialized')
t = time.time()
feed_dict = {x:testset}
output = session.run(prob, feed_dict = feed_dict)

I want to use conv5 as [inp] of tf.py_func because I cannot create a tf.placeholder and feed the intermediate value of the graph(here:conv5) in the beginning of the tf session.

However, there is an error like this:

    Initialized
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-19-2b38ea266e1a> in <module>()
      6     t = time.time()
      7     feed_dict = {x:testset}
----> 8     output = session.run(prob, feed_dict = feed_dict)
      9     #adaptivepooling5 = session.run(adappool5, feed_dict = feed_dict)
     10     print(conv5.shape)

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    765     try:
    766       result = self._run(None, fetches, feed_dict, options_ptr,
--> 767                          run_metadata_ptr)
    768       if run_metadata:
    769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
    963     if final_fetches or final_targets:
    964       results = self._do_run(handle, final_targets, final_fetches,
--> 965                              feed_dict_string, options, run_metadata)
    966     else:
    967       results = []

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1013     if handle is None:
   1014       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1015                            target_list, options, run_metadata)
   1016     else:
   1017       return self._do_call(_prun_fn, self._session, handle, feed_dict,

/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _do_call(self, fn, *args)
   1033         except KeyError:
   1034           pass
-> 1035       raise type(e)(node_def, op, message)
   1036
   1037   def _extend_graph(self):

InvalidArgumentError: 0-th value returned by pyfunc_8 is double, but expects float
     [[Node: PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_8", _device="/job:localhost/replica:0/task:0/cpu:0"](Relu_4/_3)]]
     [[Node: PyFunc/_5 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_86_PyFunc", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

Caused by op u'PyFunc', defined at:
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "/usr/local/lib/python2.7/dist-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelapp.py", line 474, in start
    ioloop.IOLoop.instance().start()
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 887, in start
    handler_func(fd_obj, events)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "/usr/local/lib/python2.7/dist-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 276, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/kernelbase.py", line 390, in execute_request
    user_expressions, allow_stdin)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/zmqshell.py", line 501, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2717, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2821, in run_ast_nodes
    if self.run_code(code, result):
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-17-90b8573e003c>", line 91, in <module>
    adaptivepool5 = tf.py_func(adaptive_pooling_np, [conv5], tf.float32)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/script_ops.py", line 189, in py_func
    input=inp, token=token, Tout=Tout, name=name)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_script_ops.py", line 40, in _py_func
    name=name)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2327, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/yifan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1226, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): 0-th value returned by pyfunc_8 is double, but expects float
     [[Node: PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_8", _device="/job:localhost/replica:0/task:0/cpu:0"](Relu_4/_3)]]
     [[Node: PyFunc/_5 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=1, tensor_name="edge_86_PyFunc", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

How can I use this numpy function in tensorflow?

Body:
Your py_func is returning a tf.float64 instead of a tf.float32, which is the declared type.

Change the line to say

newpool5 = tf.py_func(adaptive_pooling_np, [conv5], tf.float64)

and things will be fine.


问:
How to update a pull request through Github API
I want to update the title of a pull request and performing the below to achieve it :- (followed this doc https://developer.github.com/v3/pulls/#update-a-pull-request) </p>

```<code>data = {"title": "New title"}
url='https://hostname/api/v3/repos/owner/repo/pulls/80'
token = 'my-token'
headers = {'Content-type': 'application/json', 'Accept': 'application/json', 'Authorization': 'token %s' % token}
resp = requests.patch(url, data=json.dumps(data), headers=headers)

print resp.json()
</code>```

<p>What am I missing ? Please help. </p>

答:
The following worked for me:</p>

```<code>import requests

token = "my-token"
url = "https://api.github.com/repos/:owner/:repo/pulls/:number"
payload = {
    "title": "New title"
}

r = requests.patch(url, auth=("username", token), json=payload)

print r.json()
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I want to update the title of a pull request and performing the below to achieve it :- (followed this doc https://developer.github.com/v3/pulls/#update-a-pull-request)

data = {"title": "New title"}
url='https://hostname/api/v3/repos/owner/repo/pulls/80'
token = 'my-token'
headers = {'Content-type': 'application/json', 'Accept': 'application/json', 'Authorization': 'token %s' % token}
resp = requests.patch(url, data=json.dumps(data), headers=headers)

print resp.json()

What am I missing ? Please help.

Body:
The following worked for me:

import requests

token = "my-token"
url = "https://api.github.com/repos/:owner/:repo/pulls/:number"
payload = {
    "title": "New title"
}

r = requests.patch(url, auth=("username", token), json=payload)

print r.json()


问:
What is INSTALL_PARSE_FAILED_NO_CERTIFICATES error?
I was trying to change my default/main/startup (whatever you call it) activity by editing the androidmanifest.xml file. All i did was change the android:name property. however, this completely broke the entire app. when I try to install it fails and reads.

Installation error: INSTALL_PARSE_FAILED_NO_CERTIFICATES

When I tried to change it back to its previous state, it was still giving me the same error... What have I done?

答:
I found that this error can now also occur when using the wrong signing config.  As described here, Android 7.0 introduces a new signature scheme, V2. The V2 scheme signs the entire APK rather than just the JAR, as is done in the V1 scheme.  If you sign with only V2, and attempt to install on a pre-7.0 target, you'll get this error since the JARs themselves are not signed and the pre-7.0 PackageManager cannot detect the presence of the V2 APK signature.

To be compatible with all target systems, make sure the APK is signed with both schemes by checking both signature version boxes in Android Studio's Generate Signed APK dialog as shown here:

If only 7.0 targets are anticipated, then there is no need to include the V1 signature.


问:
convert large data in json format
i have a table named  mobile in which all the mobile data is contained which have more then 7000 records now i want to display in json format but some how records are not showing here is my code kindly check ..

```<code><?php
$conn = mysqli_connect("localhost","root","","test") or die ("Error ".mysqli_error($conn));
$sql = "select * from mobile";

$result = mysqli_query($conn, $sql) or die ("error" . mysqli_error($conn));
var_dump($result);

$myArray = array();

while($row = mysqli_fetch_assoc($result)){

    $myArray[] = $row;

}

mysqli_close($conn);

header('Content-Type: application/json');

//$json = file_get_contents('json.json');

/*

$myArray = array("user1" => array("firstName" => "Mike2", "lastName" => "Smith" , "age" => 34),"user2" => array("firstName" => "Mike2", "lastName" => "Smith" , "age" => 34));

*/

$json = json_encode($myArray);

echo $json;

?>
</code>```

table

答:
The problem with JSON_ENCODE in PHP is, it tends to add double quotes and escaping sequences which would increase the actual size of the JSON being imported. So, please try this. This worked for me.</p>
```<code><?php
header('Content-Type: application/json');

$conn = mysqli_connect("localhost","root","","test") or die ("Error ".mysqli_error($conn));
$sql = "select * from mobile";
$result = mysqli_query($conn, $sql) or die ("error" . mysqli_error($conn));

$myArray = array();

while($row = mysqli_fetch_assoc($result)){
    $myArray[] = $row;
}

mysqli_close($conn);

$prefix = '';
echo '[';
foreach($myArray as $row) {
  echo $prefix, json_encode($row);
  $prefix = ',';
}
echo ']';
?>
</code>```

Title: convert large data in json format

Body:
i have a table named  mobile in which all the mobile data is contained which have more then 7000 records now i want to display in json format but some how records are not showing here is my code kindly check ..

<?php
$conn = mysqli_connect("localhost","root","","test") or die ("Error ".mysqli_error($conn));
$sql = "select * from mobile";

$result = mysqli_query($conn, $sql) or die ("error" . mysqli_error($conn));
var_dump($result);

$myArray = array();

while($row = mysqli_fetch_assoc($result)){

    $myArray[] = $row;

}

mysqli_close($conn);

header('Content-Type: application/json');

//$json = file_get_contents('json.json');

/*

$myArray = array("user1" => array("firstName" => "Mike2", "lastName" => "Smith" , "age" => 34),"user2" => array("firstName" => "Mike2", "lastName" => "Smith" , "age" => 34));

*/

$json = json_encode($myArray);

echo $json;

?>

table

Body:
The problem with JSON_ENCODE in PHP is, it tends to add double quotes and escaping sequences which would increase the actual size of the JSON being imported. So, please try this. This worked for me.

<?php
header('Content-Type: application/json');

$conn = mysqli_connect("localhost","root","","test") or die ("Error ".mysqli_error($conn));
$sql = "select * from mobile";
$result = mysqli_query($conn, $sql) or die ("error" . mysqli_error($conn));

$myArray = array();

while($row = mysqli_fetch_assoc($result)){
    $myArray[] = $row;
}

mysqli_close($conn);

$prefix = '';
echo '[';
foreach($myArray as $row) {
  echo $prefix, json_encode($row);
  $prefix = ',';
}
echo ']';
?>


问:
Lua table contents separated at equal sign
I am learning Lua, and i want to use it with Rainmeter.
In Rainmeter i use an external txt file to store skin positions with the following type of lines:

```<code>pza=A1
pzb=B2
pzc=D3
... (and so on...)
</code>```

In my Lua script i made an array with reading the lines in it. So the first line is pza=A1, the second is pzb=B2, and so.
Is there any way to check only the value after the equal sign? So separating somehow the pza=A1, to get the "pza" as key, and to get "A1" as value?

Thank you very much for the help in advance!

答:
I am not sure if I understood but try something like this where line would be the line you read from the file.

```<code>local line = "test1=100"

local delim = string.find(line, "=")
key = string.sub(line, 1, delim - 1)
val = string.sub(line, delim + 1, -1)

print("Key: "..key.." Val:"..val)
</code>```

This will print:

Key: test1 Val:100

Body:
I am learning Lua, and i want to use it with Rainmeter.
In Rainmeter i use an external txt file to store skin positions with the following type of lines:

pza=A1
pzb=B2
pzc=D3
... (and so on...)

In my Lua script i made an array with reading the lines in it. So the first line is pza=A1, the second is pzb=B2, and so.
Is there any way to check only the value after the equal sign? So separating somehow the pza=A1, to get the "pza" as key, and to get "A1" as value?

Thank you very much for the help in advance!

Body:
I am not sure if I understood but try something like this where line would be the line you read from the file.

local line = "test1=100"

local delim = string.find(line, "=")
key = string.sub(line, 1, delim - 1)
val = string.sub(line, delim + 1, -1)

print("Key: "..key.." Val:"..val)

This will print:

Key: test1 Val:100


问:
asp.net user control binding
i created a user control with a custom property in the asp.net like the following. In the aspx page that uses this user control i have something like the following. The user control is in a FormView's EditItemTemplate

```<code><uc1:MyControl ID="c1" runat="server" CountryCode='<%# this.DropDownCountry.SelectedValue %>' Value1='<%# Bind("Value1Col") %>' />
</code>```

I am trying to use the CountryCode in the Page_Load method of the user control, but the value has not be populated.

My question is at which stage in the control's life cycle does the bounded value gets populated? I tried assigning value directly like the following and it does get its value at the Page_Load method.

```<code><uc1:MyControl ID="c1" runat="server" CountryCode="CA" Value1='<%# Bind("Value1Col") %>' />
</code>```

thanks,

the uc1:MyControl has the following property:

```<code>[Browsable(true)]
[Bindable(true, BindingDirection.TwoWay)]
[DefaultValue(0)]
[PersistenceMode(PersistenceMode.Attribute)]
public string CountryCode
{
    get { return _countryCode; }
    set { _countryCode = value; }
}
</code>```

答:
Since you're using databinding syntax you need to call DataBind method on your control - you can add this to the Page_Load method of the aspx page like so:</p>

```<code>protected void Page_Load(object sender, EventArgs e)
{
    c1.DataBind();
}
</code>```

Title: asp.net user control binding

Body:
i created a user control with a custom property in the asp.net like the following. In the aspx page that uses this user control i have something like the following. The user control is in a FormView's EditItemTemplate

<uc1:MyControl ID="c1" runat="server" CountryCode='<%# this.DropDownCountry.SelectedValue %>' Value1='<%# Bind("Value1Col") %>' />

I am trying to use the CountryCode in the Page_Load method of the user control, but the value has not be populated.

My question is at which stage in the control's life cycle does the bounded value gets populated? I tried assigning value directly like the following and it does get its value at the Page_Load method.

<uc1:MyControl ID="c1" runat="server" CountryCode="CA" Value1='<%# Bind("Value1Col") %>' />

thanks,

the uc1:MyControl has the following property:

[Browsable(true)]
[Bindable(true, BindingDirection.TwoWay)]
[DefaultValue(0)]
[PersistenceMode(PersistenceMode.Attribute)]
public string CountryCode
{
    get { return _countryCode; }
    set { _countryCode = value; }
}

Body:
Since you're using databinding syntax you need to call DataBind method on your control - you can add this to the Page_Load method of the aspx page like so:

protected void Page_Load(object sender, EventArgs e)
{
    c1.DataBind();
}


问:
Javascript - New line, \n, not effective while pulling in JSON from external file
JSON:

```<code>{"data": {
  "heading": "Module 2: Discussion Boards 1",
  "description": "Students were asked to post to the Discussion board the responses they gathered from interviewing an experienced online instructor.\n Students were then asked to read the posts and offer feedback to their colleagues.",
  "tabs": {
    "tabItem": [
      {
        "value": "Edgar and Amy Conflict"
      },
      {
        "value": "Oliver's Document"
      },
      {
        "value": "Two Professors?"
      }
    ]
  }
}
}
</code>```

Javascript:

```<code>var actual_JSON = JSON.parse(response);

             document.getElementById("heading").innerHTML = actual_JSON.data.heading;
             document.getElementById("description").innerHTML = actual_JSON.data.description;
</code>```

Result

The new line (\n) does not work. I have tried \\n but to no avail.

When I tried var actual_JSON = JSON.strigify(response);
in the console.log I can get the new line if I replace \n with
 in the JSON but then it does not work as an object so the rest of the code breaks down.

I have seen many posts in this regard and tried the solutions presented, but I'm missing something.

Thanks for any help!

答:
The new line is not effective because it's in an HTML element

```<code><p> Hello this new line will
not work </p>
</code>```

Will result in "Hello this new line will not work" in one line

But

```<code><p> Hello this new line will <br />
work </p>
</code>```

Will result in
 "Hello this new line will
 work" in two lines line

For HTML use

Body:
JSON:

{"data": {
  "heading": "Module 2: Discussion Boards 1",
  "description": "Students were asked to post to the Discussion board the responses they gathered from interviewing an experienced online instructor.\n Students were then asked to read the posts and offer feedback to their colleagues.",
  "tabs": {
    "tabItem": [
      {
        "value": "Edgar and Amy Conflict"
      },
      {
        "value": "Oliver's Document"
      },
      {
        "value": "Two Professors?"
      }
    ]
  }
}
}

Javascript:

var actual_JSON = JSON.parse(response);

             document.getElementById("heading").innerHTML = actual_JSON.data.heading;
             document.getElementById("description").innerHTML = actual_JSON.data.description;

Result

The new line (\n) does not work. I have tried \\n but to no avail.

When I tried var actual_JSON = JSON.strigify(response);
in the console.log I can get the new line if I replace \n with
 in the JSON but then it does not work as an object so the rest of the code breaks down.

I have seen many posts in this regard and tried the solutions presented, but I'm missing something.

Thanks for any help!

Body:
The new line is not effective because it's in an HTML element

<p> Hello this new line will
not work </p>

Will result in "Hello this new line will not work" in one line

But

<p> Hello this new line will <br />
work </p>

Will result in
 "Hello this new line will
 work" in two lines line

For HTML use <br />


问:
Python: how pass string as a function's argument
I have a dataframe with US state abbreviations:

```<code>state
tx
ca
fl
wa
ny
az
</code>```

I'm trying to get full names with the us.states module

```<code>df['state_ru'] = df.state.apply(lambda x: us.states.x.upper().name)
</code>```

And it returns

```<code>AttributeError: module 'us.states' has no attribute 'x'
</code>```

I'm unclear how to pass the x into the us.states module to produce what I'm looking for.

Expected results:

```<code>state  state_ru
tx     Texas
ca     California
fl     Florida
wa     Washington
ny     New York
az     Arizona
</code>```

答:
The us.states module has a lookup method you can use:

```<code>import us
df['state_ru'] = df.state.apply(lambda x: us.states.lookup(x).name)
df
</code>```

Body:
I have a dataframe with US state abbreviations:

state
tx
ca
fl
wa
ny
az

I'm trying to get full names with the us.states module

df['state_ru'] = df.state.apply(lambda x: us.states.x.upper().name)

And it returns

AttributeError: module 'us.states' has no attribute 'x'

I'm unclear how to pass the x into the us.states module to produce what I'm looking for.

Expected results:

state  state_ru
tx     Texas
ca     California
fl     Florida
wa     Washington
ny     New York
az     Arizona

Body:
The us.states module has a lookup method you can use:

import us
df['state_ru'] = df.state.apply(lambda x: us.states.lookup(x).name)
df