Rectangle 27 0

np.nan has type float: arrays containing it must also have this datatype (or the object datatype) so you may need to recast arr before you try to assign the value. The error arises because the string value 'nan' can't be converted to an integer type to match arr's type.

The string 'nan' is interpreted as np.nan if you have a float array:

>>> arr = arr.astype('float')
>>> arr[arr == 0] = 'nan' # or use np.nan
>>> arr
array([[ nan,   1.,   2.],
       [  3.,   4.,   5.]])

python - Replace zeros in a numpy array with nan - Stack Overflow

python arrays numpy nan
Rectangle 27 0

I converted query to use LINQ instead of the Lambda methods. It is easier for me to read queries when they are written in LINQ syntax.

How does the db.Location relate to pg.ListSelectedGrpDescID.Count == 0? What should db.Location return if it is 0? I left this part of the query out for now.

It can be a good idea to break the problem up into steps when trying to find a solution. This is a first step towards the solution.

First, we can refactor the ListGrpHolder ID's into another statement. This will return only the int value and make the ListLocation query easier to read.

var SelectedIds = ListGrpHolder.Select(pg => pg.ListSelectedGrpDescID).SelectMany(i => i);
var ListLocation = (from loc in db.Locations
                    from grp in loc.GroupLocations
                    where SelectedIds.Contains(grp.GrpDescID)
                    select loc).ToList();

If we are not able to simplify or change the query to get the results you need, then we can look into using an Expression Tree.

asp.net mvc 2 - Expression Tree error: Unable to create a constant val...

asp.net-mvc-2 entity-framework-4 linq-to-entities
Rectangle 27 0

This error is caused because you are trying to pass as a parameter or function return value a single integer when it expects an array. You didn't include enough in your code to be more specific. (Which line is the error on? What is employeeIDFilter? What is DoSomething?)

kindly have a look at the edited post, i have added brief explanation

asp.net - value of type integer cannot be converted to 1-dimensional a...

asp.net vb.net
Rectangle 27 0

I presume lineNo is declared as Integer? Clicking "Cancel" on the InputBox will return an empty string, and an emptry string cannot be converted to a numeric value. That's what your error says. So you should get the result of the InputBox, which always returns a String, and convert it in a separate step, maybe with Integer.TryParse.

inputbox - Conversion from string "" to type 'Integer' is not valid. -...

vb.net inputbox
Rectangle 27 0

yes, it is, but you will have to make a flat version of the object you are wanting to create, because the validation with attributes only runs AFTER MVC has converted your data into the model. which, when your value is an int, will fail to validate if the user did not enter an int, and you will get a MVC error message in stead of your errormessage.

can you post the object you are wanting to make?

with a flat version i mean all datetimes and ints are stings in the flat version.

[DisplayName("Square meters")]
    [PosNumberNoZero(ErrorMessage = "need a positive number, bigger than 0")]
    public string squaremeters { get; set; }

in the same file

public class PosNumberNoZeroAttribute : ValidationAttribute {
    public override bool IsValid(object value) {
        if (value == null) {
            return true;
        }
        int getal;
        if (int.TryParse(value.ToString(), out getal)) {

            if (getal == 0)
                return false;

            if (getal > 0)
                return true;
        }
        return false;

    }
}
public class PosNumberAttribute : ValidationAttribute {
    public override bool IsValid(object value) {
        if (value == null) {
            return true;
        }
        int getal;
        if (int.TryParse(value.ToString(), out getal)) {

            if (getal >= 0)
                return true;
        }
        return false;
    }
}

sorry. for the trouble I should have known that. Just had a brain fart

no problem. i hope you get it to work for yourself ;)

Why not use decimal.TryParse or something? In that way, you can support more number types than just integers

c# - How to do Integer model validation in asp.net mvc 2 - Stack Overf...

c# asp.net-mvc int model-validation
Rectangle 27 0

I had this problem once, I was passing an integer value as the first parameter for the ActionLink method (when the expected value is a string), so I got this error that was caused for the mistyped parameter data type. I just converted the parameter to string and it worked (ie: myModel.integerProperty.ToString()).

.net - ASP.NET MVC View throwing CS1061 error related to type of model...

asp.net .net asp.net-mvc
Rectangle 27 0

Parse is specifically to parse strings and gives you more control over what format the string may be. Convert.ToInt will handle almost any type that can be converted in the first place. What is more error prone depends on your input and the variations you expect. int.TryParse is robust in that it won't throw an exception, the pitfall is that it is easy to hide the parsing error. This choice depends on what you want to do? Do you want to provide feedback, have detailed parsing error info, use alternative / default values?

asp.net c# int.Parse or Convert.toInt - Stack Overflow

c# asp.net-mvc
Rectangle 27 0

CREATE OR REPLACE PACKAGE IH_FORMS_TRIAL.STRING_TO_TABLE IS
  type grs_list_row is record ( varchar_list varchar2(512), int_list number,  date_list date );
  type grs_list_tab is table of grs_list_row;

FUNCTION ft_string_to_table(av2_list varchar2, av2_delimiter varchar2 := ',', av2_list_type varchar2 := 'V',  av2_date_mask varchar2 := 'DD-MON-YY')  return grs_list_tab   PIPELINED;

END STRING_TO_TABLE;
/


CREATE OR REPLACE package body IH_FORMS_TRIAL.STRING_TO_TABLE IS
    FUNCTION ft_string_to_table(av2_list varchar2, av2_delimiter varchar2 := ',', av2_list_type varchar2 := 'V',  av2_date_mask varchar2 := 'DD-MON-YY')  return grs_list_tab   PIPELINED
             IS


    /**********************************************************************************************************
    http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/x/Table_Functions_Cursor_Expressions/Pipelined_Table_Functions.htm
    http://www.akadia.com/services/ora_pipe_functions.html
    PIPLELINED TABLE FUNCTION


    PURPOSE -   
    ------------------
            This function takes a string as input and returns a table.
            The table that is returned will normally be used in an SQL "IN" clause
    =====================================================================================
    ARGUMENTS
    ------------------
            av2_list - this is a comma delimited list of values that will be converted into single rows of a table
            av2_delimiter - this is a character value and should only be one character long.
                                         It is the delimiter that is between valid values in the av2_list
                                         The default value is a comma ','
            av2_list_type - This function can return various types of lists or tables
                           For this parameter
                                   A value of 'V' will return a table of varchar2
                                   A value of 'I' will return a table of integers
                                   A value of 'D' will return a table of dates
            av2_date_mask - This is required if the value of av2_list_type is 'D' for date
                            The date mask will be used by the Oracle built-in TO_DATE function
                            A default value of 'DD-MON-YY' is used


    =====================================================================================
    RETURNS
                            Table of values for input to an IN portion of a WHERE clause
    =====================================================================================
    EXAMPLES

    SELECT * FROM <TABLE> WHERE <VARCHAR_COLUMN> IN (select varchar_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('has986, abc454')));
    SELECT * FROM <TABLE> WHERE <INTEGER_COLUMN> IN (select int_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('1,2,3,4,5,6,7,8,9', ',', 'I')));
    SELECT * FROM <TABLE> WHERE <DATE_COLUMN> IN (select date_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('2010-03-04, 2010-03-05', ',', 'D', 'YYYY-MM-DD')));

    =====================================================================================
    TEST CASES


             select varchar_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('has986, abc454', ',', 'V'));
             select int_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('1,2,3,4,5,6,7,8,9', ',', 'I'));
             select date_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('04-mar-10, 05-mar-10', ',', 'D'));
             select date_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('2010-03-04, 2010-03-05', ',', 'D', 'YYYY-MM-DD'));


             test using and invalid list type
             Use Y instead of V, I or D
             Should produce an error
             select varchar_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('has986, abc454', ',', 'Y'));


             test using a date format that does not match the date format passed
             Should produce an error
             select date_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('2010-03-04, 2010-03-05', ',', 'D', 'YYYY-MON-DD'));
             select date_list from  table (ih_core_owner.core.ft_string_to_table.ft_string_to_table('2010-MAR-04, 2010-MAR-05', ',', 'D', 'YYYY-MM-DD'));

    ----------

    =====================================================================================
    REVISION HISTORY
      Called by misc systems
      ----------------------------------------------------------------
      Modification History

      Date               User            Description
      ------------       --------------  ----------------------------------
      2006-03-03         HarvS           Initial Release
      2010-04-09         HarvS           Translated from SQL Server to ORACLE
                                         Combined functions that returned lists of varchar, integer, and date into one function with optional parameters

     REVISION HISTORY
      ----------------
      Build Version    -  11.02.01.001
      Build Date       -  08-June-2010
      Modified By      -  has986
      Description      -  Created                                             



    ******************************************************************************/

                --local variable of type grs_list_row
          lrs_row grs_list_row;


                 E_INVALID_LIST_TYPE EXCEPTION;

        li_delimiter_position int;
        li_previous_delimiter_position int;
        lv2_value varchar2(512);

    BEGIN

           if av2_list_type not in ('V', 'I', 'D') THEN
                 raise E_INVALID_LIST_TYPE;
            end if;

        li_delimiter_position := 1;
        li_previous_delimiter_position := 1;

        li_delimiter_position := INSTR(av2_list, av2_delimiter,  li_delimiter_position);

        while li_delimiter_position > 0 loop
              lv2_value := substr(av2_list, li_previous_delimiter_position, (li_delimiter_position - li_previous_delimiter_position));
               --Trim the value
              lv2_value := RTRIM(LTRIM(lv2_value));

              if length(lv2_value) > 0 THEN
                  if av2_list_type = 'V' then --varchar
                     lrs_row.varchar_list := lv2_value;
                  elsif av2_list_type = 'I' then --integer
                     lrs_row.int_list := to_number(lv2_value);
                  elsif av2_list_type = 'D' then --date
                     lrs_row.date_list := to_date(lv2_value, av2_date_mask);
                  end if;
                  pipe row ( lrs_row );
              END IF;


              --set the new delimiter positions
            li_previous_delimiter_position := li_delimiter_position + 1;
            li_delimiter_position := INSTR(av2_list, av2_delimiter,  li_delimiter_position + 1);
        END loop;

          --Get the last value
          lv2_value := SUBSTR(av2_list, li_previous_delimiter_position, length(av2_list));

        --Trim the value
        lv2_value := RTRIM(LTRIM(lv2_value));

        if length(lv2_value) > 0 THEN
        --Insert the value into the in memory table
              if av2_list_type = 'V' then --varchar
                 lrs_row.varchar_list := lv2_value;
              elsif av2_list_type = 'I' then --integer
                 lrs_row.int_list := to_number(lv2_value);
              elsif av2_list_type = 'D' then --date
                 lrs_row.date_list := to_date(lv2_value, av2_date_mask);
              end if;
              pipe row ( lrs_row );
         END IF;

         return;


        EXCEPTION

             WHEN E_INVALID_LIST_TYPE then


                                    /*
                                        The developer should be notified of this error during the development phase.
                                    */
                    raise_application_error (-20001, av2_list_type || ' is not a valid type. Valid types are (V, I, or D)' );


            WHEN OTHERS THEN
                        RAISE;
    END ft_string_to_table;
end string_to_table;
/




select * FROM table( string_to_table.ft_string_to_table('1, 2, 3', ',', 'I'));

select * FROM table( string_to_table.ft_string_to_table('fred, wilma, betty, barney', ',', 'V'));

select * FROM table( string_to_table.ft_string_to_table('2011-5-1, 1950-1-1, 1960-1-2, 2023-12-1', ',', 'D', 'yyyy-mm-dd'));

Hope this works for you. I have seen some other code that does this as well. For what its worth, this is much easier to do in Microsoft SQL Server

c# - problem using Oracle parameters in SELECT IN - Stack Overflow

c# sql oracle parameters ora-01722
Rectangle 27 0

The variable reading is a OleDbDataReader which can't be used to assign an integer, that's the reason for the error. But you don't need a DataReader anyway if you use ExecuteScalar:

Dim maxNumber As Int32 = Convert.ToInt32(cmd.ExecuteScalar())
TextBox1.Text = maxNumber.ToString

Suggesting a check for DBNull on MAX

Yes, maybe, hope that he never adds a where to the sql.

Value of type 'Integer' cannot be converted to 'System.Data.OleDb.OleD...

vb.net type-conversion
Rectangle 27 0

@Inherits System.Web.Mvc.ViewPage(Of MyApp.Core.Domain.User)
@ModelType MyApp.Core.Domain.User

The base type for Razor pages is System.Web.Mvc.WebViewPage. Or as you've discovered you can just use the @ModelType keyword.

asp.net mvc 3 - MVC Error (Razor) Value of type 'System.Web.Mvc.MvcHtm...

asp.net-mvc-3 razor
Rectangle 27 0

yes, it is, but you will have to make a flat version of the object you are wanting to create, because the validation with attributes only runs AFTER MVC has converted your data into the model. which, when your value is an int, will fail to validate if the user did not enter an int, and you will get a MVC error message in stead of your errormessage.

can you post the object you are wanting to make?

with a flat version i mean all datetimes and ints are stings in the flat version.

[DisplayName("Square meters")]
    [PosNumberNoZero(ErrorMessage = "need a positive number, bigger than 0")]
    public string squaremeters { get; set; }

in the same file

public class PosNumberNoZeroAttribute : ValidationAttribute {
    public override bool IsValid(object value) {
        if (value == null) {
            return true;
        }
        int getal;
        if (int.TryParse(value.ToString(), out getal)) {

            if (getal == 0)
                return false;

            if (getal > 0)
                return true;
        }
        return false;

    }
}
public class PosNumberAttribute : ValidationAttribute {
    public override bool IsValid(object value) {
        if (value == null) {
            return true;
        }
        int getal;
        if (int.TryParse(value.ToString(), out getal)) {

            if (getal >= 0)
                return true;
        }
        return false;
    }
}

sorry. for the trouble I should have known that. Just had a brain fart

no problem. i hope you get it to work for yourself ;)

Why not use decimal.TryParse or something? In that way, you can support more number types than just integers

c# - How to do Integer model validation in asp.net mvc 2 - Stack Overf...

c# asp.net-mvc int model-validation