77from .abstract_parameter_type import AbstractParameterType
88from ._util import get_swagger_for_list , get_swagger_for_nested_dict
99from ._constants import SWAGGER_FORMAT_CONSTANTS
10+ from warnings import warn
1011
1112
1213class PandasParameterType (AbstractParameterType ):
1314 """
1415 Class used to specify an expected parameter as a Pandas type.
1516 """
1617
17- def __init__ (self , sample_input , enforce_column_type = True , enforce_shape = True , apply_column_names = True ,
18+ def __init__ (self , sample_input , enforce_column_type = True , enforce_shape = True , apply_column_names = False ,
1819 orient = 'records' ):
1920 """
20- Construct the PandasParameterType object.
21+ Construct the PandasParameterType object. An important note regarding Pandas DataFrame handling; by default,
22+ Pandas supports integer type column names in a DataFrame. However, when using the built in methods for
23+ converting a json object to a DataFrame, unless all of the columns are integers, they will all be converted
24+ to strings. This ParameterType uses the built in methods for performing conversion, and as such
25+ `deserialize_input` has the same limitation. It is recommended to not use a mix of string and integer
26+ type column names in the provided sample, as this can lead to inconsistent/unexpected behavior.
2127
2228 :param sample_input: A sample input dataframe. This sample will be used as a basis for column types and array
2329 shape.
@@ -28,8 +34,10 @@ def __init__(self, sample_input, enforce_column_type=True, enforce_shape=True, a
2834 :param enforce_shape: Enforce that input shape must match that of the provided sample when `deserialize_input`
2935 is called.
3036 :type enforce_shape: bool
31- :param apply_column_names: Apply column names from the provided sample onto the input when `deserialize_input`
32- is called.
37+ :param apply_column_names: [DEPRECATED] Apply column names from the provided sample onto the input when
38+ `deserialize_input` is called. Disabled by default, as there is no guaranteed order for dictionary keys,
39+ so it's possible for names to be applied in the wrong order when `deserialize_input` is called. The
40+ property is deprecated, and will be removed in a future update.
3341 :type apply_column_names: bool
3442 :param orient: The Pandas orient to use when converting between a json object and a DataFrame. Possible orients
3543 are 'split', 'records', 'index', 'columns', 'values', or 'table'. More information about these orients can
@@ -42,6 +50,10 @@ def __init__(self, sample_input, enforce_column_type=True, enforce_shape=True, a
4250 super (PandasParameterType , self ).__init__ (sample_input )
4351 self .enforce_column_type = enforce_column_type
4452 self .enforce_shape = enforce_shape
53+
54+ if apply_column_names :
55+ warn ('apply_column_names is a deprecated parameter and will be removed in a future update' ,
56+ DeprecationWarning , stacklevel = 2 )
4557 self .apply_column_names = apply_column_names
4658
4759 if orient not in ('split' , 'records' , 'index' , 'columns' , 'values' , 'table' ):
0 commit comments