Skip to content

Replace object type comparisons with string comparisons when pandas dtype is of type string #728

@genedan

Description

@genedan

Pandas now uses a default string type when it used to default to object type.

https://pandas.pydata.org/docs/dev/whatsnew/v3.0.0.html#dedicated-string-data-type-by-default

This will cause existing code that checks for type object to fail, such as line 424 in _drop_func:

def _drop_func(self, factor):
# get the appropriate backend for nan_triangle and nan_to_num
xp = factor.get_array_module()
# turn single drop_valuation parameter to list if necessary
drop_list = self.drop if isinstance(self.drop, list) else [self.drop]
# get an starting array of weights
arr = factor.nan_triangle.copy()
# accommodate ldf triangle as factor, where the dimensions are '12-24'
dev_list = (
factor.development.str.split("-", expand=True)[0]
if factor.development.dtype == object
else factor.development.astype("string")
)
# create ndarray of drop_list for further operation in numpy
drop_np = np.asarray(drop_list)
# find indices of drop_np
origin_ind = np.where(
np.array([factor.origin.astype("string")]) == drop_np[:, [0]]
)[1]
dev_ind = np.where(np.array([dev_list]) == drop_np[:, [1]])[1]
# set weight of dropped factors to 0
arr[(origin_ind, dev_ind)] = 0
return xp.nan_to_num(arr)[None, None]

As far as I can tell, this is the only place in the package where this happens and causes test failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effort > Brief 🐇Small tasks expected to take a few hours up to a couple of days.Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to join our community!Impact > Minor 🔷Small, backward compatible change. Treat like a patch release (e.g., 0.5.8 → 0.5.9).

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions