Data Conversions Between Excel and Python¶
xlSlim always tries to determine the appropriate conversions when passing data between Excel and Python. Without type hints xlSlim will handle numbers, strings, bools and datetimes. Adding type hints allows xlSlim to handle Python dictionaries and instances of custom classes. Lists of simple data types are also better handled when type hints are provided.
See Passing simple data types, Passing Python objects, Passing Python dictionaries, Passing lists, numpy Arrays, pandas Series and pandas DataFrames for worked examples.
Function Inputs¶
Python functions without type hints are handled well enough for many use cases.
Type in Excel | Type passed to Python |
---|---|
integer | float |
double | float |
string | string |
bool | bool |
datetime | float |
Range | Wrapped .Net array of objects. |
For more advanced use cases, Python type hints open up the full potential of xlSlim.
Type in Excel | Type passed to Python | Supported Type Hints |
---|---|---|
integer | integer |
|
double | float |
|
string | string |
|
bool | bool |
|
datetime | datetime |
|
cached object handle | Python object |
|
Range of ints | Wrapped .Net array of objects. |
|
Range of doubles | Wrapped .Net array of doubles. |
|
Range of strings | Wrapped .Net array of objects. |
|
Range of datetimes | Wrapped .Net array of objects. |
|
Range | np.ndarray | np.ndarray |
|
pd.Series | pd.Series |
|
pd.DataFrame | pd.DataFrame |
Range of cached object handles | List of Python objects |
|
Range of cached object handles | List of np.ndarray |
|
Range of cached object handles | List of pd.Series |
|
Range of cached object handles | List of pd.DataFrame |
|
Note
The Python wrapped .Net arrays are not converted to native Python lists for performance reasons. The wrapped arrays behave exactly the same as native Python lists with one important difference - they are immutable. Additionally, type checking is only done when a function expects a list of floats, in other cases lists of objects are passed and the objects may be any Excel type.
Function Outputs¶
The results of Python functions are handled equally well with or without type hints.
Type in Python | Result type in Excel |
---|---|
integer | double |
float | double |
bool | bool |
datetime | float (this is correct as all Excel datetimes are floats) |
string | string |
dict | cached object handle |
Python object (an instance of a custom class) | cached object handle |
np.ndarray | cached object handle |
pd.Series | cached object handle |
pd.DataFrame | cached object handle |
list of integers | Range of doubles |
list of floats | Range of doubles |
list of bool | Range of bool |
list of strings | Range of strings |
list of strings, ints, floats and bools | Range of strings, ints, floats and bools |