Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function: 'lowest' common type #157

Open
majidaldo opened this issue Dec 22, 2020 · 2 comments
Open

function: 'lowest' common type #157

majidaldo opened this issue Dec 22, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@majidaldo
Copy link

majidaldo commented Dec 22, 2020

Sometimes going through a whole array is not needed. You have the types of the subsets of the array and you just want to get a compatible data type for all subsets.

A common scenario when assembling horrible csvs is that the same column might be inferred as different types in different csvs. For example, (float <-- int). Worst case is to 'fall back' to string.

@majidaldo majidaldo added the enhancement New feature or request label Dec 22, 2020
@ieaves
Copy link
Collaborator

ieaves commented Dec 23, 2020 via email

@ieaves
Copy link
Collaborator

ieaves commented Dec 23, 2020

I should add, If you were interested in making a PR for this use case it would be more than welcome.

A basic implementation would look something like this:

def cast_along_path(series, graph, path, state={}):
  base_type = path[0]
  for vision_type in path[1:]:
      relation = graph[base_type][vision_type]["relationship"]
      series = relation.transform(series, state)
  return series

Which could be invoked

T = typeset
s = pd.Series([your data])
path = [Generic, Object, String]

# Type Detection
new_s = cast_along_path(s, T.base_graph, path)

# Type Inference
new_s = cast_along_path(s, T.relation_graph, path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants